wordpress get current page id inside and outside of loop

WordPress get current page id or post id is a common query while developing WordPress theme, as there many time it needed to filter or make a link, now the below code will help you to get the current page or post id inside and outside of the loop

WordPress get current page id Outside the loop

To get the post or page id outside of loop users need to design the post or query globally to get the page or post content and then have to write the code to get the id.

Example code is given below

ID;
?>

or

post->ID;
?>

WordPress get current page id Inside the loop

To get a page or post id inside the loop just need to write the code $post->ID; or get_the_ID()

Example code is given below

ID;
?>

or


In this post, we have seen how to get current page id or post id in WordPress

Please provide your comments to make the site more useful and better.

Thanks for reading

Share The Post On -

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.