Home › Forums › ACF PRO › Google Maps enqueue scripts › Reply To: Google Maps enqueue scripts
I use this in one of my in house themes. It simply checks if the current page has a locations field which would require a google map. We then check if google_maps_api function exists in case we forgot to include it. then we enqueue the script to be added in the footer. You can change true to false if you want it in the header.
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
function wpb_adding_scripts() {
global $post;
if(!empty(get_field('locations',$post->ID)){
if(function_exists('google_maps_api')){
$apiKey=google_maps_api();
if($apiKey){
wp_register_script('googleMapsAPI',
'https://maps.googleapis.com/maps/api/js?key='.$apiKey,
'',
true
);
wp_enqueue_script('googleMapsAPI');
}
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.