WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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!

share|improve this answer
Note: this will be required for repository-hosted Themes once WordPress 3.4 is released. – Chip Bennett Jun 12 '12 at 19:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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