acf/fields/google_map/api

Last updated Mar 31, 2023

Description

Used to modify the url parameters used to load the Google Maps JS API.

Primarily, this filter exists to set a Google API key, however, it may also be used to customize other_params used in the google.load function.

Changelog

  • Added in version 5.3.10

Parameters

apply_filters( 'acf/fields/google_map/api', $args );

$args

(array) Array of url parameters. – libraries
(string) A comma separated list of libraries to load. Defaults to “places”. ~~~ ‘libraries’ => ‘places’, ~~~

  • key
    (string) A Google Maps API key. Defaults to an empty string.

    'key' => '',
    
  • client
    (string) Optional. A Google API client ID. Defaults to an empty string.

    'client' => '',
    
  • callback
    (string) Optional. A global JavaScript function to call when the API has loaded. Defaults to Function.prototype (a no-op).

    'callback' => 'Function.prototype',
    

Example

This example demonstrates how to register a Google API key to be used when loading the Google Maps JS library.

functions.php

<?php
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
function my_acf_google_map_api( $args ) {
    $args['key'] = 'xxx';
    return $args;
}

Related