Skip to content

Instantly share code, notes, and snippets.

@grayghostvisuals
Created October 17, 2012 18:41
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/3907296 to your computer and use it in GitHub Desktop.
Save grayghostvisuals/3907296 to your computer and use it in GitHub Desktop.
There are many ways to skin a cat when it comes to implementing wp_title() - http://ziadrahhal.com/2012/05/recommended-wp_title-filter-in-wordpress
// http://ziadrahhal.com/2012/05/recommended-wp_title-filter-in-wordpress
// http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
// http://codex.wordpress.org/Function_Reference/wp_title
// Title tag filter
// required for themes
// a custom callback function that displays a meaningful title
// depending on the page being rendered
function wp_flex_title_filter( $title, $sep, $sep_location ) {
// add white space around $sep
$sep = ' ' . $sep . ' ';
$site_description = get_bloginfo( 'description' );
if ( $site_description && ( is_home() || is_front_page() ) )
$custom = $sep . $site_description;
elseif( is_category() )
$custom = $sep . 'Category';
elseif( is_tag() )
$custom = $sep . 'Tag';
elseif( is_author() )
$custom = $sep . 'Author';
elseif( is_year() || is_month() || is_day() )
$custom = $sep . 'Archives';
else
$custom = '';
// get the page number (main page or an archive)
if( get_query_var( 'paged' ) )
$page_number = $sep . 'Page' . get_query_var( 'paged' );
// get the page number (post with multipages)
elseif( get_query_var( 'page' ) )
$page_number = $sep . 'Page' . get_query_var( 'page' );
else
$page_number = '';
// Comment the 4 lines of code below and see how odd the title format becomes
if( $sep_location == 'right' && !( is_home() || is_front_page() ) ) {
$custom = $custom . $sep;
$title = substr( $title, 0, -2 );
}
// return full title
return get_bloginfo( 'name' ) . $custom . $title . $page_number;
}
/// add function 'wp_flex_title_filter()' to the
// wp_title filter, with priority 10 and 3 args
add_filter( 'wp_title', 'wp_flex_title_filter', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment