• Resolved drcherrychocolate

    (@drcherrychocolate)


    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • <?php echo get_the_title(); ?> will display the current page’s title.

    Thread Starter drcherrychocolate

    (@drcherrychocolate)

    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.

    Thread Starter drcherrychocolate

    (@drcherrychocolate)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying special title in the header how?’ is closed to new replies.