I have developed a javascript plugin retrieving data for my website (no wordpress here). The user can simply add it to its website with a div (the container of the plugin) and a script tag (the plugin). This plugin displays a google map with some fancy information.

As wordpress does not allow the user to add its own js, I try to write a wordpress plugin bypassing this with the wp_register/wp_enqueue functions. My javascript is loaded (so is the google maps api) however the google map is not displayed (the google api is called from my plugin and not from the wp queue scripts).

Any idea/suggestion ?

EDIT: Here is the code of the wp plugin + what is used in the posts to display the widget (can't show the plugin as it is hundreds of lines long, I can only say that it's working on a classical server) :

define ( 'EVP_IDS_PATTERN',  '/\[EVP_WIDGET:\{ID:"(\w+)"\},\{TYPE:"(\w+)"\}\]/i' );

functon insert_evp_widget ( $text ) {
    if ( is_single ( ) || is_page ( ) ) { 
    $ids = [];
    // The page contains an evp collection ID
    if ( preg_match ( EVP_IDS_PATTERN, $text, $ids ) ) {

        // We add the script to the page (css is direclty loaded from the widget)
            wp_register_script ( 'evp_widget', 'http://widget.evp.com/javascripts/app.js' );
            wp_enqueue_script ( 'evp_widget' );

           // We add the widget container in the page
           $widget = '<div data-evp-id="' . $ids[1] . '" data-evp-type="' . $ids[2] . '"></div>';
           $text .= $widget;

           // Remove the wordpress widget tag from the article.
           $text = preg_replace ( EVP_IDS_PATTERN, '', $text );

           return $text;

add_filter ( 'the_content', 'insert_evp_widget' );

Post data used to display the widget :


The widget is supposed to be able to display two kinds of widget : an album and a map version. The album version works (with a API call using json-p), however, the map version does not work (API call using json-p + google maps call). The google scripts are in the page.

  • 2
    Without seeing your code: no chance.
    – kaiser
    Commented Aug 20, 2013 at 9:43
  • @kaiser : I have added the wp plugin + the post data, however as the album version works on wp, both work on a cassical html page and the google scripts are loaded, I am not sure whether it is useful.
    – Simon
    Commented Aug 20, 2013 at 11:44
  • Two questions: 1) What dependencies (e.g. jQuery) does your script have, and 2) What happens if you bundle the script with the Plugin, rather than enqueue it from an external source? Commented Aug 20, 2013 at 12:07
  • 1) One dependency called vendor.js, stored in the same dir than the widget and called using the absolute HTTP path : widget.evp.com/javascripts/vendor.js (it contains infobox.js, used to make some fancy WindowBox when you click on a marker). 2) No idea, I'll try.
    – Simon
    Commented Aug 20, 2013 at 12:28
  • 1
    Oh god... I had forgotten to set the size of the map in the map container. The plugin was working perfectly fine.
    – Simon
    Commented Aug 20, 2013 at 13:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.