How to get title from current page in WordPress

This article was written by in July 1, 2015, & may not be posted on other sites!
Original source url for this article: How to get title from current page in WordPress

How to get title from current page in WordPress.
Working with theme files or templates in WordPress, it’s usefull to get the ID of the current page you are on. Having the current page ID, you can print out all sorts of elements from that page, for example the current page title. This is how to get title from current page in WordPress.

Use the current page ID to get the title or any other element from the current page. This is how to get title from current page in WordPress. Full php code.

 

Get title from current page in WordPress

The first step is to get the page ID of the current page. When having the ID of the current page, one can print out any element from that page, for example the title of the current page. Use this php code in any theme file or template in WordPress:

global $post;
$id = $post->ID;
$theTitle = get_the_title($id);

 

Print out the title from current page in WordPress

To print out the current page title, use this php code in any theme file or template:

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 *