WordPress.org

Support

Support » How-To and Troubleshooting » recent post title showing as page title.

recent post title showing as page title.

  • Hello,

    So here is the situation. I have no plugins running, so I am sure its not the plugins. I have cleaned up my database a couple of times and thats not it either.

    In my header file I have the following code

    <div class="container headtitle">
    			<div id="b" class="last">
    				<div id="title"><h1><?php echo get_the_title(); ?></h1></div>
    	</div>
    </div>

    Which basically shows the page title on each page, except its not working for the ‘Blog’ page. On the blog page it shows me the title for the most recent blog post.

    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Michael

    @alchymyth

    you need to get the page id for the ‘blog page’ or ‘page for posts’ from the options table in the database;

    change the one line:

    <div id="title"><h1><?php if( is_home() && get_option('page_for_posts') ) { $posts_page_id = get_option('page_for_posts'); echo get_the_title($posts_page_id); } else { echo get_the_title(); ?></h1></div>

    do you have the same page title problem for archive pages?

    Hi alchymyth,

    Thanks for the reply.

    Yes, the same thing has been happening on the archive page. The code you gave me doesn’t return anything different. It’s the same thing. I am sure there is a fix for this.

    Thanks for your help though.

    Moderator Michael

    @alchymyth

    I forgot to check if you have a static front page and set the ‘blog’ page at the same time? ( http://codex.wordpress.org/Creating_a_Static_Front_Page )

    if not, and the ‘blog’ page is your home page, then my code would not work;

    this adapted code would show the title ‘Home’ on the ‘blog’ page, and the respective page title otherwise:

    <div id="title"><h1><?php if( is_home() && get_option('page_for_posts') ) { $posts_page_id = get_option('page_for_posts'); echo get_the_title($posts_page_id); } elseif( is_home() ) { echo 'Home'; } else { echo get_the_title(); ?></h1></div>

    it might be helpful if you could post a link to your site.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘recent post title showing as page title.’ is closed to new replies.