If you want to get the Current page id in WordPress without using any plugin?
Then you came to the right place.
We have simple snippets that will help you to easily display current page or post id outside the loop.
Just follow the below steps:
WordPress Get Current Page ID
First of all, copy the below-embedded code and paste it into your WordPress theme’s functions.php file.
Code to display Current Page or Post ID
Save the file and view the result in your browser.
It also works same as the above.
Just the difference from
global $post and
global $wp_query the above code is, it ($wp_query) can display tons of things if you want.
Read also: Get Current Page Slug
Hope the above code helped you.
Let us know your opinion about the above codes and ask questions if you have.
Don’t forget to share this Get Current Post or Page ID in WordPress.