Custom Fields
Re-Envisioned
Support General Issue for Map field output when page/content is loaded dynamically

  • Creator
    Topic
  • #17924
    Resolved ambrdigital
    Participant

    Hi there,

    On our Contact page we are using the map field to output a Google map with our business on it. This loads just fine. However, when the page is loaded through AJAX dynamically (specifically using barba.js), the map does not output.

    There are no console errors, but it looks like the google maps scripts aren’t being loaded into the DOM.

    Do you have a solution for loading the map field when it is called dynamically via AJAX? Let me know. Thank you so much

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #17945
    Anh Tran
    Keymaster

    Hi,

    Can you try calling this JS after the page is loaded via Ajax:

    $( document ).trigger( 'mb_ready' );

    #17964
    ambrdigital
    Participant

    Hi Ahn,

    Thanks for the reply. Unfortunately that didn’t seem to trigger the map or load the relevant scripts 🙁 any other ideas?

    #17985
    Anh Tran
    Keymaster

    I see. Maybe you need to manually enqueue the Google maps script on the page before running the snippet above. Something like this:

    add_action( 'wp_enqueue_scripts', function() {
        RWMB_Map_Field::admin_enqueue_scripts( ['api_key' => 'your key', 'language' => 'en'] );
    } );
    #18129
    ambrdigital
    Participant

    Perfect, thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Newsletter

Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.


grid gear info copy caret-up caret-down trash