how to get the current page id in wordpress using jquery
jquery, wordpress
Solution
function get_current_page_id() {
var page_body = $('body.page');
var id = 0;
if(page_body) {
var classList = page_body.attr('class').split(/\s+/);
$.each(classList, function(index, item) {
if (item.indexOf('page-id') >= 0) {
var item_arr = item.split('-');
id = item_arr[item_arr.length -1];
return false;
}
});
}
return id;
}
Add this function to your code. You can now get the page id by using:
var id = get_current_page_id();
Problem
how to get a page id in wordpress using jquery alone.I am planing to change some styles of a page using a custom script for which i need to know page id.