Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] Code from our blog post - Passing Variables between PHP and jQuery - http://www.limecanvas.com/passing-variables-between-php-and-jquery/
// 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' );
// 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' );
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
You can’t perform that action at this time.