Last active
January 1, 2016 12:09
-
-
Save zeropointdevelopment/8142553 to your computer and use it in GitHub Desktop.
[WordPress] Code from our blog post - Passing Variables between PHP and jQuery - http://www.limecanvas.com/passing-variables-between-php-and-jquery/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load our jQuery script | |
function lc_load_jquery(){ | |
wp_enqueue_script('lcjquerytest', get_stylesheet_directory_uri() . '/js/lc-jquery.js', array('jquery'), '1.0', true); | |
global $post; | |
$data = array( 'somestring' => 'pooky', 'post_id' => $post->ID, 'post_title' => $post->post_title ) | |
wp_localize_script( 'lcjquerytest', 'lc_jqpost_info', $data ); | |
} | |
add_action( 'wp_enqueue_scripts', 'lc_load_jquery' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load our jQuery script | |
function lc_load_jquery(){ | |
wp_enqueue_script('lcjquerytest', get_stylesheet_directory_uri() . '/js/lc-jquery.js', array('jquery'), '1.0', true); | |
} | |
add_action( 'wp_enqueue_scripts', 'lc_load_jquery' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery("#clickme").click(function () { | |
var msg = 'somestring='+lc_jqpost_info.somestring; | |
msg += ' post_id='+lc_jqpost_info.post_id; | |
msg += ' post_title='+lc_jqpost_info.post_title; | |
alert( msg ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment