Get the current post ID as a variable in Javascript
Question
I’m trying to echo the post ID in a post Javascript and not having any luck.
var post_id = '123'; // works fine
var post_id = '<?php global $post; echo $post->ID; ?>'; // echos 'ID; ?>'
var post_id = '<?php echo $post->ID;?>'; // echos 'ID; ?>'
Is there a correct way to echo the post ID?
0
id, javascript, posts
4 years
2020-02-21T08:39:09-05:00
2020-02-21T08:39:09-05:00 0 Answers
95 views
0
Leave an answer