Skip to content

Instantly share code, notes, and snippets.

@strarsis
Last active January 8, 2018 00:13
Show Gist options
  • Save strarsis/c2242cc5ab122990faceb1df3c6237d8 to your computer and use it in GitHub Desktop.
Save strarsis/c2242cc5ab122990faceb1df3c6237d8 to your computer and use it in GitHub Desktop.
Set Google Maps key for ACF and ACF PRO
<?php
// Add this code to plugin or theme
// Authorize API for project:
// see https://console.developers.google.com/apis/api/places_backend?project=_
const GOOGLE_API_KEY = 'the-API-key';
// ACF
add_filter('acf/fields/google_map/api', function ($value) {
return array(
'libraries' => 'places',
'key' => GOOGLE_API_KEY
);
});
// ACF PRO
function my_acf_init() {
acf_update_setting('google_api_key', GOOGLE_API_KEY);
}
add_action('acf/init', 'my_acf_init');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment