-2

my script is

function($) {
   var google_map_address = $('#address').text();
$(function () {
$('#gmap').gmap3({
    marker: {
        address: google_map_address 
    },
    map: {
        options: {
            zoom: 14
        }
    }
}); });})(jQuery);

and my php code is

    init_shortcode();
    function init_shortcode() {
    $shortcodes = array(
    'gmap' => 'spyrowebs_gmap');
    foreach( $shortcodes as $tag => $func )
        add_shortcode( $tag, $func );
    }  
    function spyrowebs_gmap( $atts = array(), $content = '' ) {
    $defaults = array(
        'address' =>'',
      );
    $atts = shortcode_atts( $defaults, $atts );
    extract( $atts );
    $address=$address;
    return ' <div class="gmap" id="gmap"><div id="address" style="display:none">'.$address.'</div></div>';
}

but this does not work i want to create a shortcode like

[gmap address="your address"]

now what is the problem when i assign a value to javascript variable like

var google_map_address = 'your address';

then its work while in the above its not working please any help. when i put the above code in my theme its work but when i use it in my plugin its not work.

6
  • possible duplicate of Pass PHP variable to javascript Commented Jun 11, 2014 at 14:33
  • Please don't use the wordpress.org tag. Commented Jun 11, 2014 at 14:36
  • Is the lacking ( at the start of the first piece of JavaScript code a typo? Commented Jun 11, 2014 at 14:37
  • what do you mean? engelen Commented Jun 11, 2014 at 14:49
  • The function($) {, shouldn't that be (function($) {? Commented Jun 11, 2014 at 14:55

2 Answers 2

1

Hey Guys i got the solution.

just include my script in footer instead of header.

add_action('wp_footer', 'spyrowebs_gmap_enqueue_scripts');
0

Try using html() instead if text() function.

Try:

var google_map_address = $('#address').html();
3
  • Matt, you should not post multiple answers to a question. If you need to add/remove/modify anything, please do it in an edit to you original answer Commented Jun 11, 2014 at 16:24
  • I just forgot one more thing, if you find your answer to be inappropriate or totally wrong, delete it before posting a new answer Commented Jun 11, 2014 at 16:26
  • 2
    @PieterGoosen Cool, will do - Thanks for the heads up on that :-) Commented Jun 11, 2014 at 16:58

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.