Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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
2  
Note: this will be required for repository-hosted Themes once WordPress 3.4 is released. –  Chip Bennett Jun 12 '12 at 19:04
add comment

Your Answer

 
discard

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.