Forums

[resolved] Displaying special title in the header how? (5 posts)

  1. DrCherryChocolate
    Member
    Posted 4 months ago #

    What if I want to display a page's title in the header.php template?

    Extra points if I can overwrite the title in the page template file, because what might work in content-single.php might not work in category.php or page.php or frontpage.php

  2. James Edmonston
    Member
    Posted 4 months ago #

    <?php echo get_the_title(); ?> will display the current page's title.

  3. DrCherryChocolate
    Member
    Posted 4 months ago #

    Can anyone go for the bonus points? Because on my category pages, that displays the first post in that category when I'd like the title to be the category.

    I suppose I can drop a big series of "if" statements into the header like

    if ( is_singular() )
      get_the_title()
    else if ( is_category() )
      single_cat_title( '', true )
    else if ( is_front_page() )
      ...

    But it seems inelegant.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

  5. DrCherryChocolate
    Member
    Posted 4 months ago #

    Oh, right I hadn't thought to look in the <title> tag further up in the header. That gives me wp_title(''); and other stuff to work with.

Reply

You must log in to post.

About this Topic

Tags