When constructing the HTML <title>
attribute in a theme, I found there is a convenient hook for modifying wp_title.
However, a quick review of themes indicates using this hook is not common practice. In fact, if you look at TwentyEleven, you'll see this in header.php:
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;
wp_title( '|', true, 'right' );
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );
?></title>
It seems to me that this could be pulled into functions.php
, and be replaced with:
(in functions.php)
add_filter( 'wp_title', 'twentyeleven_title_filter' );
function twentyeleven_title_filter( $title ) {
// All that title logic here
}
(in header.php)
<title><?php wp_title(); ?></title>
I'm fairly new to theme development, so forgive me if this is common knowledge - but why not just modify wp_title in the filter instead of in the header? Is there a limitation somewhere?
There is a bit of debate about wp_title that is going on in this ticket, but from what I can gather it still sounds like the filter would work - am I wrong?