Skip to content

Instantly share code, notes, and snippets.

@akamola
Created February 16, 2021 09:06
Show Gist options
  • Save akamola/7ed7d7d1b415c94ef8bfaa6327cd8ab2 to your computer and use it in GitHub Desktop.
Save akamola/7ed7d7d1b415c94ef8bfaa6327cd8ab2 to your computer and use it in GitHub Desktop.
WordPress + Advanced Custom Fields Pro: Enable Google Maps API
<?php
// Add this code to the themes functions.php
const GOOGLE_MAPS_API_KEY = 'Your Google Maps API Key';
// Ensure Advanced Custom Fields Pro (ACF Pro) is enabled
//
// Check if plugin is enabled without additionally include the plugin manager for is_plugin_active()
// @see https://developer.wordpress.org/reference/functions/is_plugin_active/#comment-2427
if ( in_array( 'advanced-custom-fields-pro/acf.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function my_acf_init() {
// Set Google Maps API Key
// @see https://www.advancedcustomfields.com/resources/google-map/
acf_update_setting( 'google_api_key', GOOGLE_MAPS_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