WordPress.org

Ready to get started?Download WordPress

Forums

Set variable in javascript and using in my shortcode (2 posts)

  1. Spyro webz
    Member
    Posted 1 month ago #

    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.

  2. Spyro webz
    Member
    Posted 1 month ago #

    hey any one which can solve my problem?

Reply

You must log in to post.

About this Topic