WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a Google Maps plugin.

My problem is that the function that initializes the map, csf_map_maker_js(), is getting called too early-- before the div is defined (at least that's what I think is the problem).

In the PHP, I've got:

$csf_map_output .= '<div id="csf_map_canvas" style="width:'. $atts['width'].'px; height: '. $atts['height'] .'px;"></div>'; 

$csf_map_output .= '<script>var csf_map_params = ' .  json_encode( $atts ) .  '; csf_map_maker_js( csf_map_params );</script>';  

return $csf_map_output;

I don't think that the csf_map_canvas div is ready when the function is called.

In the javascript script, the csf_map_maker_js() function is defined outside of jQuery(document).ready(function() {}); . If I move it inside, will the csf_map_canvas div be ready when the function is called.? If so, how do I change the function call in the PHP script in order to call a function in an anonymous function? How do I get around the scope issue?

Is there another way?

share|improve this question

if u think that is the problem simply do:

$csf_map_output .= '<script>
    var csf_map_params = ' .  json_encode( $atts ) .  ';
    csf_map_maker_js( csf_map_params );

I don't see any scope issues with the above code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.