How to get the current page id of post or page outside loop?

By | April 24, 2014

Use the below code to get the current page id or post id, but outside loop,

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

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.