Show Page Title and Content of the ‘Posts Page’ in WordPress

When you set a static front page and at the same time set a Posts Page, WordPress will automatically use index.php (or home.php *) to display the Posts Page; as described in the Codex, you’ll lose the output of the title and content of that page.
To show this information on the Posts Page, for instance as an introduction for the posts, add some code to index.php (or home.php):

<?php //this is to output the page title and content for a 'page for posts' page as set under  'settings' - 'reading'
	if( is_home() && !is_paged() && get_option('page_for_posts') ) { 
	$posts_page_id = get_option('page_for_posts'); ?>			
	<header class="entry-header">
		<h1 class="entry-title"><?php echo get_the_title($posts_page_id); ?></h1>
	</header><!-- .entry-header -->
	<?php $posts_page = get_page( $posts_page_id ); ?>
	<div class="entry-content posts-page-entry-content">
	<?php echo apply_filters('the_content', $posts_page->post_content); ?>
	</div><!-- .posts-page-entry-content -->	
<?php } ?>

5 Replies to “Show Page Title and Content of the ‘Posts Page’ in WordPress”

  1. Dear Michael,
    I am really new to wordpress development. I want to add title to every page & post manually. Can you please give me code as you have given for meta description i n your post.

  2. After much scratching of the head, and trawling through various forums – i finally found this, which was the solution to my problem!

    Massive thanks 😀

  3. Hi Alchymyth,

    I copied the index.php to my child theme and add your code to it, it works like a charm!

    However, I am wondering if there is anyway that we can further improve this method. For example, I want to make this index.php as one of my page templates. I found when I change the name of index.php, it doesn’t work. Would you mind adding the solution to your post, I think that will benefit lots of WordPress users.

    Thanks and regards,

    Matthew

    1. Hi Matthew,
      for a page template, the page title and content are directly available with a ‘default’ loop, which you could have before the custom template code. see the Codex; or check the WordPress support forum for possible solutions.
      cheers,
      Michael

Leave a Reply to Michael Cancel reply

Your email address will not be published. Required fields are marked *