How to check if there is a title WordPress. Page title or not?

This article was written by in April 8, 2015, & may not be posted on other sites!
Original source url for this article: How to check if there is a title WordPress. Page title or not?

How to check if there is a title WordPress. Page title or not?
Do you need to check if there is a page title to a post or page in WordPress before executing your php code? This is how to check if there is a page title to a post or page in WordPress or not.

How to check if there is a title WordPress. Page title or not?

 

How to check if there is a title WordPress. Page title or not?

Do you need to check if there is a page title to a post or page in WordPress? Having a page title means if the author has filled in the title field in a post or page. To check if a post or page has a page title in WordPress, use this php code in any template or theme file:

Inside the loop:

<?php
if(get_the_title()){
//your code if there is a title
}else{
//your code if there is not a title
}
?>

Outside the loop, in this case from page ID 12:

<?php
if(get_the_title(12)){
//your code if there is a title
}else{
//your code if there is not a title
}
?>

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

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