• Resolved jasurdeury

    (@jasurdeury)


    Hello, i have a plugin that adds a google maps view directly when adding a new post.
    It works on frontend but in backend i can’t add the google maps API to make it work.

    Following the javascript example, I added this snippet:

    add_action( 'wp_head', function () { ?>
    	<script src="https://maps.googleapis.com/maps/api/js?key=[MY_API_KEY]&callback=initMap" type="text/javascript"></script>
    <?php } );

    I’ve activated this snippet for the admin-side only, but it doens’t have much effect.
    I think I’m missing something obvious (maybe wp_head is wrong?) ,but unfortunately I’m a noob in this.

    Could you help me with this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hello,

    To add script in the admin area, you need to use the admin_head hook instead of wp_head:

    add_action( 'admin_head', function () { ?>
    	<script src="https://maps.googleapis.com/maps/api/js?key=[MY_API_KEY]&callback=initMap" type="text/javascript"></script>
    <?php } );
    Thread Starter jasurdeury

    (@jasurdeury)

    Hi, thanks for your quick response!
    Unfortunately it still doesn’t have much effect, this is how the map appears on backend: https://prntscr.com/m8xyle

    The map is working on frontend, so i figured I just had to copy the script in backend. Maybe there’s still something else wrong in my snippet?

    Plugin Author Shea Bunge

    (@bungeshea)

    It would really depend on what other scripts/code you are using to display the map.

    Thread Starter jasurdeury

    (@jasurdeury)

    Hi, you are right.
    The correct script to edit was buried in an admin subfolder of my theme (was using meta-box class), i would have found it more quickly if i did a search for “wp_enqueue_script” in all folders, to see where the google script was located.

    Anyway, thank you very much for your help and patience, your plugin is awesome!

    Plugin Author Shea Bunge

    (@bungeshea)

    Glad to hear you could get it working!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add Google Maps API snippet in Dashboard admin backend’ is closed to new replies.