How to get current page ID outside the loop?

4

Try

global $post;
echo $post->ID;

or (I don’t know the difference)

global $wp_query;
echo $wp_query->post->ID;

Tags:

Leave a Reply

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