How to get current page ID outside the loop?

Try

global $post;
echo $post->ID;

or (I don’t know the difference)

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

Leave a Comment