Current page id returns the incorrect value

I need to capture the current page id, execute some conditional script in footer, in my own plugin function hooks to wp_footer.

Here is my plugin code, but page id returning wrong value?

<?php
/*
Plugin Name: My Plugin
Author: GS
Version: 1.1
*/
Function footer_page_id()
{
global $post;
echo ‘<div> page_id:’.$post->ID.'</div>’;// output wrong value
global $wp_query;
echo ‘page_id:’.get_the_ID();// output wrong value
echo ‘post_id:’.$wp_query->post->ID; // output wrong value
echo ‘page_id:’.$wp_query->get_queried_object_id(); // output always 0
echo'</br>’;exit;
}
add_action(‘wp_footer’, ‘ footer_page_id ‘);
?>

Thanks in advance.

Read more here:: Current page id returns the incorrect value

Leave a Reply

Your email address will not be published. Required fields are marked *