0

I have:

  • a static front page "Home"
  • a page with all my posts "My posts"
  • all the other post/pages from the blog "Post x / Page y"

and each one of them should display its title in the header. I'm almost there, this is my code in header.php

<?php if( is_home() && get_option('page_for_posts') ) : ?>
    <h1><?php echo apply_filters('the_title',get_page( get_option('page_for_posts') )->post_title); ?> (posts page - "My posts")</h1>
<?php endif; ?>

<?php if ( is_front_page() ) : ?>
    <h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a> (static front page "Home")</h1>

<?php else : ?>
    <h1><a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(''); ?></a> (all the other pages - "Any page/post")</h1>
<?php endif;?>

My problem is that when I'm on "My posts" it shows both the "My posts" title and the title of the latest post. I need only the former. Any suggestion?

0

Ok solved.

<?php if ( is_front_page() && !is_home() ) :?> 
    <h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<?php elseif ( is_home() && get_option('page_for_posts') ): ?>
    <h1><?php echo apply_filters('the_title',get_page( get_option('page_for_posts') )->post_title); ?></h1>
 <?php else : ?>
    <h1><a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(''); ?></a></h1>
<?php endif; ?>

with a little help from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.