ACF Google Maps plugin and custom template
-
Having a small issue getting custom template to display a Google Maps plugin.
Setup: Using Insert Pages to display CPT/ACF fields, using a custom template.
Issue: ACF has a field type “Google Maps” which can store a Google Maps address. It needs some additional code to fetch and display the location in a map in the frontend: https://www.advancedcustomfields.com/resources/google-map/
I got the API key and was able to get the address object from Google, but I don’t know how and where to add the helper code and viewer code in order to make it load and show up in the frontend.
What is the proper way to make the helper code available to the custom template?
Tried:
- Added helper script styles to theme’s custom CSS
- Added helper script jQuery plugin using wp_enqueue_script() to the theme’s functions.php
- Added helper script Google include using wp_enqueue_script()
- Added dependant viewer code to custom template
Here’s the custom template:
<?php /** * Template Name: Lodge Template * Template Post Type: lodge * * Template for displaying ACF for a lodge. * * @package understrap */ // Exit if accessed directly. defined( 'ABSPATH' ) || exit; ?> <article <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <div class="entry-content lodge-content"> <div> <?php $stack = InsertPagesPlugin::get_instance()->inserted_page_ids; $lodge_id = end($stack); $emblem = get_field('emblem', $lodge_id); ?> <?php if ( empty ( $emblem ) ): ?> Emblem is empty! <?php else: ?> Emblem: <img src="<?php echo $emblem['url']; ?>" alt="<?php echo $emblem['alt']; ?>" /> <?php endif; ?> </div> <!-- .image --> </div><!-- .entry-content.lodge-content --> </article><!-- #post-## --> <?php $location = get_field('location'); if( $location ) { // Loop over segments and construct HTML. $address = ''; foreach( array('street_number', 'street_name', 'city', 'state', 'post_code', 'country') as $i => $k ) { if( isset( $location[ $k ] ) ) { $address .= sprintf( '<span class="segment-%s">%s</span>, ', $k, $location[ $k ] ); } } // Trim trailing comma. $address = trim( $address, ', ' ); // Display HTML. echo '<div>' . $address . '.</div>'; }
Template loads and displays other elements, but not the map. Tried clearing the cache.
I guess my question is how do I make custom styles and scripts available to a custom template?
Thanks!
- This topic was modified 1 year, 10 months ago by .
- This topic was modified 1 year, 10 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘ACF Google Maps plugin and custom template’ is closed to new replies.