[Resolved] Conditional in the content-page.php file

Home Forums Support [Resolved] Conditional in the content-page.php file

Home Forums Support Conditional in the content-page.php file

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1364301
    Dan

    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

    #1364305
    David
    Staff
    Customer Support

    Hi there,

    simpler way is to use a Layout Element:

    https://docs.generatepress.com/article/layout-element-overview/

    You can disable the Content Title.
    Set Display Rules to Entire Site and Exclude Pages.

    #1364638
    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

    #1364729
    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

    #1364915
    Tom
    Lead Developer
    Lead Developer

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

    #1364917
    Dan

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

    #1364920
    Tom
    Lead Developer
    Lead Developer

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

    #1364922
    Dan
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.