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:

     * 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 ) );


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?

1 Answer 1


It's been a while since I've asked this, and I've built several themes in that timeframe. The answer I've come up with is "use the filter". There is no limitation to doing this, and it makes other developers' jobs much easier, as they only need to filter the output (vs. trying to do output buffering).

In short, just filter it!

  • 2
    Note: this will be required for repository-hosted Themes once WordPress 3.4 is released. Jun 12, 2012 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.