Skip to content

Instantly share code, notes, and snippets.

@tammyhart
Created October 16, 2013 15:43
Show Gist options
  • Save tammyhart/7009954 to your computer and use it in GitHub Desktop.
Save tammyhart/7009954 to your computer and use it in GitHub Desktop.
Echo WordPress "Posts Page" title
// blog title
function tammyhart_blog_title( $title = 'Blog' ) {
if ( get_option( 'show_on_front' ) == 'page' ) {
$page_id = get_option( 'page_for_posts' );
$title = get_the_title( $page_id );
}
if ( is_category() )
$title = 'Category: ' . single_cat_title( '', false );
elseif ( is_author() ) {
$object = get_queried_object();
$title = 'Author: ' . $object->data->display_name;
}
elseif ( is_tag() )
$title = 'Tag: ' . single_tag_title( '', false );
elseif ( is_tax() ) {
$tax = get_taxonomy( get_query_var( 'taxonomy' ) );
$title = $tax->labels->singular_name . ': ' . single_term_title( '', false );
}
elseif ( is_day() )
$title = 'Archive: ' . get_the_time( 'F jS, Y' );
elseif ( is_month() )
$title = 'Archive: ' . get_the_time( 'F, Y' );
elseif ( is_year() )
$title = 'Archive: ' . get_the_time( 'Y' );
elseif ( is_post_type_archive() )
$title = $wp_query->queried_object->label;
elseif ( is_search() )
$title = 'Search: ' . get_search_query( );
echo $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment