Skip to content

Instantly share code, notes, and snippets.

@grayghostvisuals
Created October 17, 2012 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grayghostvisuals/3907306 to your computer and use it in GitHub Desktop.
Save grayghostvisuals/3907306 to your computer and use it in GitHub Desktop.
This approach was posted via theme reviewers mailing list and unanimously agreed upon as the correct implementation.
function wpflex_filter_wp_title( $title ) {
global $wp_query, $s, $paged, $page;
if ( !is_feed() ) {
$sep = __('»');
$new_title = get_bloginfo('name').' ';
$bloginfo_description = get_bloginfo('description');
if ((is_home () || is_front_page()) && !empty($bloginfo_description) && !$paged && !$page) {
$new_title .= $sep.' '.$bloginfo_description;
}
elseif (is_single() || is_page()) {
$new_title .= $sep.' '.single_post_title('', false);
}
elseif (is_search() ) {
$new_title .= $sep.' '.sprintf(__('Search Results: %s'),
esc_html($s));
}
else
$new_title .= $title;
if ( $paged || $page ) {
$new_title .= ' '.$sep.' '.sprintf(__('Page: %s'),max( $paged,
$page ));
}
$title = $new_title;
}
return $title;
}
add_filter( 'wp_title', 'wpflex_filter_wp_title' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment