How to get the current page id of post or page outside loop? Post author By Rajeshkannan Post date April 24, 2014 Categories In WordPress Code Snippets No Comments on How to get the current page id of post or page outside loop? Use the below code to get the current page id or post id, but outside loop, global $wp_query; echo $wp_query->post->ID;