Skip to content

Instantly share code, notes, and snippets.

@jonbrockett
Created January 17, 2019 14:36
Show Gist options
  • Select an option

  • Save jonbrockett/5cc8cbc20f8fa2c3f7bde1ea1f5e3197 to your computer and use it in GitHub Desktop.

Select an option

Save jonbrockett/5cc8cbc20f8fa2c3f7bde1ea1f5e3197 to your computer and use it in GitHub Desktop.
Get Posts (Blog) Page Title (Custom WP Function)
/** The Posts (Blog) Page Title */
require_once( 'library/get-posts-page-title.php' );
<?php
/**
* Get and Display the Posts (Blog) Page Title
* 04/26/2018
* @author Jonathan Brockett
*
* Requires: WordPress @link https://codex.wordpress.org/
*/
/**
* Gets the posts (blog) page title
* @return string The page title of the posts pages, usually the blog page
*/
function get_the_posts_page_title() {
$page_for_posts = get_option( 'page_for_posts' ); // Gets the page the posts (blog) uses
$posts_page_title = get_the_title($page_for_posts);
return $posts_page_title;
}
/**
* Displays the posts (blog) page title
*/
function the_posts_page_title() {
echo get_the_posts_page_title();
}
<?php
/**
* The Posts Page Title (The Blog Page)
*/
?>
<?php if( is_home() && !is_front_page()): ?>
<header>
<h1 class="entry-title"><?php the_posts_page_title(); ?></h1>
</header>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment