Forums

Need static title for posts page... if/else in header? (2 posts)

  1. halfacre
    Member
    Posted 11 months ago #

    I'm using a child theme for andreas09, and I've moved the page title tag from page.php to header.php (works better for layout purposes). The snippet of code I moved is this:

    <h1><?php the_title(); ?></h1>

    This works fine except on the posts page (I have a static home page), where I would like a static title that would read "Updates & Comments" per my client's wishes. On the posts page it instead takes the title of the first post.

    I figure a simple little if/else statement should do the trick, but I have a tenuous grasp of PHP syntax at best. Intuition and experience have so far failed me. ;)

    I found that if I insert the following above the code posted above, I get both titles on the posts page (as I expected):

    <?php if( is_home() ) :?>
    <h1>Updates & Comments</h1>
    <?php endif;?>

    I'm guessing I need to move the first code snippet into the second as an "else" statement (in other words, if the page is a posts page, use the Updates & Comments title, otherwise, grab the page title). But how do I do that properly?

    Thanks all!

  2. vtxyzzy
    Member
    Posted 11 months ago #

    I think this is what you need:

    <?php if( is_home() ) :?>
      <h1>Updates & Comments</h1>
    <?php else: ?>
      <h1><?php the_title(); ?></h1>
    <?php endif;?>

Reply

You must log in to post.

About this Topic

Tags