Retrieve The Posts Page in WordPress

Stumbled on this today when I setup WordPress to have a static page as the home and another page — a posts page — to show the blog entries. There is NO template tag or single function for this! Not to worry, I made one 🙂

Place this in your theme’s function.php file:

function get_posts_page_url() {
  if( 'page' == get_option( 'show_on_front' ) ) {
    $posts_page_id = get_option( 'page_for_posts' );
    $posts_page = get_page( $posts_page_id );
    $posts_page_url = site_url( get_page_uri( $posts_page_id ) );
  }
  else {
    $posts_page_url = site_url();
  }
  return $posts_page_url;
}

Then, in your various other template files you can use this function to get the URL of the “posts page”:

<a href="<?php echo get_posts_page_url(); ?>" >LINK</a>

There you go! Based on code found HERE.

Leave a Reply