How to find current page ID in WordPress using php?

This article was written by in July 1, 2015, & may not be posted on other sites!
Original source url for this article: How to find current page ID in WordPress using php?

How to find current page id in WordPress using php? 
Working with dynamic templates in WordPress, it’s usefull to ge the page ID of the current page you are on. This is how to find current page id in WordPress using php?

Working with dynamic templates in WordPress, it's usefull to get the page ID of the current page. This is how to find page ID in WordPress using php.

 

Find current page ID in WordPress using php

To find the page ID of the current page, use this php code in theme files or templates:
global $post;
$id = $post->ID;

 

To print title from current page ID in WordPress using php

When you have the current page ID you can print out all sorts of elements, for example the title of that page. To print the title of the current page you are on, use this php code in theme files or templates:
global $post;
$id = $post->ID;
echo get_the_title($id);

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

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