Site logo

Archived topic

Conditional in the content-page.php file

7 replies · Started by Dan on July 15, 2020

Viewing posts 1–8 of 8

Hi
I would like to show the page title only when using the default (page.php) template. For other page templates used in the site the title should be hidden.
I created this conditional in the content-page.php file but it is not working this code below hides the title for all page templates.

if (is_page_template('page.php')){	
the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' );
							
		}

Any ideas why?

Thanks,
Dan

Thanks David, but there is no option to work with page templates in the layout element.
Would you know what would be the way to make it work with the condition?

Thanks
Dan

I found a solution that works:

if(basename(get_page_template()) === 'page.php'){
the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' );					
	}

I don't know why the previous code didn't work but this does.
adding 'basename' made it work.

Dan

That's strange, your original code should definitely work as long as nothing is interfering with it.

The only thing I can think about is that WP isn't recognizing page.php as the default template and therefore ignoring the condition.

Ah, that could be it. It's possible that is_page_template() looks for custom page templates as opposed to default ones.

This archived topic is closed to new replies.