Discuss: The Page Title in WordPress Themes

WordPress is a content management system. It allows the user to create and edit types of content, be them post, pages or custom post types and classify them with taxonomies, categories, tags or custom taxonomies. Almost every bit of content a WordPress site outputs is easy to control by the maintainer of that WordPress site. Almost, because there’s one piece of content that’s notoriously hard to fully control. That bit is the title, often also called “meta title”. The way that title is displayed is determined, in large part, by your theme.

Now I bring this up for a single reason: the title is the single most important piece of content on a page relating to SEO. In the most recent update of SEOmoz’s ranking factors, the presence of a keyword in the title was agreed by SEO’s to have an “influence value” of 94.4 out of 100. That’s huge.

In WordPress’ most recent default theme, dubbed Twenty Eleven, the content of that title tag is determined by the following code:

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


With all due respect, I hate that. The reason I hate that is that it means that on the front page of your site, no matter what you do, your title will always be of this format:


On other pages, it will be:


So we effectively hardcode in our design templates the way we output one of our most important bits of content on a page. That’s very far from the separation of design & content that the web community at large has been striving for over the last few decades.

If you’re now thinking, “hey, I’m using that theme and I have another page title for my homepage”, you might be right, I’ll get to that. The reason you’re able to do that is also the reason why I regularly get questions about my WordPress SEO plugin and theme X, Y or Z having issues with the title.

The bad solution: Output Buffering the page title

I don’t want to spend this entire article explaining what output buffering is, so if you don’t know, this is a rather simple explanation. This process is used by most big SEO plugins. What they do is: catch the output of a page, look for the <title>, fix the contents of that title, return the output. For the record: if you check the “Force rewrite titles” box on the Titles page of my SEO plugin, it does just that. The reason my plugin has had issues with titles is exactly that: I don’t have that box checked by default.

Now one can argue over whether output buffering in general is a bad idea or not, the way it’s done here is arguably bad, although the only current working solution. It uses way more resources than should be needed to change the title and, possibly worse, it effectively disallows other plugins that don’t do the buffering to have an influence on the title. On top of that, in my testing, on most servers it adds about 0.5 seconds to the page load time.

The good solution: something new in core

For quite a while, I thought that changing the way we, as a community, use wp_title would be a fix to this. I no longer think that it is. The reason for that is that it would create all sorts of other issues, with themes and plugins alike. In fact, Andrew Nacin already tried to do that a while back, see this changeset, and reverted the changeset because the output buffering plugins broke because of it. I think we need a new function, specifically aimed at displaying the page title. Ideally this function would hook into wp_head and would be using the theme_supports functionality.

I’ve been working with Andrew on a patch, which has been heavily discussed on this Trac ticket. I have good hopes that something along these lines will go into core, but would love to know your opinion.

Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

27 Responses

  1. Ben HusonBy Ben Huson on 5 September, 2011

    Joost, I 100% agree with you on this. The should be able to be fully customised and filtered via plugins.

    That’s not to say that if a theme author wanted to influence the default output of the title tag they couldn’t, but it should all be done via functions.php so that it can be overwritten by other plugins – like you wonderful SEO one for example ;)

    Reading through the trac ticket, I like the idea of introducing a new wp_title_tag() that includes tags in its output so it’s use cannot be abused for other purposes, and move towards that being standard. I’m sure all the main theme developers would implement it straight away if that was ‘the way to do it’.

    • Joost de ValkBy Joost de Valk on 5 September, 2011

      The way the patch works now, all they have to do is remove their <title> tags, core will take care of the rest.

      • Ben HusonBy Ben Huson on 5 September, 2011

        Nice, I presume that means the title get’s inserted by wp_head?

        • Joost de ValkBy Joost de Valk on 5 September, 2011

          Yeah, but only if wp_title hasn’t fired yet :-)

  2. RarstBy Rarst on 5 September, 2011

    I’ve seen sparks fly on this, but I am not sure I follow.

    1. We have function with filtered output. The concept kinda works for most of the things in WP.

    2. We had default theme making a mess instead of using a filter.

    3. It was changed to use a filter, then changed back to a mess. Apparently because of SEO plugin judging by your post and “aioseop.diff” rollback in trac. Why exactly? Plugin broke? Fix plugin…

    Now proposed solutions are:

    1. Introduce new template tag with filter. Why? We already have template tag with filter. How is new template tag with new filter addresses anything?

    2. Decouple title from template. Seems a little to fragile to me. And template tag we already have won’t magically disappear.

    I think I am missing some nuance here – why does current template tag with filter needs fixing? Because theme developers use it in wrong way? Duh… get that issue in a long long line of such. :)

    • Joost de ValkBy Joost de Valk on 5 September, 2011

      A fix on wp_title would not be backwards compatible with 99% of themes, which is a problem. Making a new function would allow for themes to implement the better, new behavior, without breaking the old.

      Also, on principle: the title is content and should be output outside of the theme’s reach.

      • RarstBy Rarst on 5 September, 2011

        But what is wrong with wp_title() right now? It is template tag with a filter. What can’t it do that new template tag with new filter will be able to?

        I understand the issue with hardcoded mess in template. I just don’t see how introducing new function improves the situation.

        • Joost de ValkBy Joost de Valk on 5 September, 2011

          The issue is that if we suddenly start adding the site name to WP_title by default, 9 out of 10 themes break. We wanted 1 new function that takes care of the entire title.

          • RarstBy Rarst on 5 September, 2011

            I am probably fuzzy on big picture, because I mostly use Hybrid and if I need title changed I filter wp_title hook.

            > The issue is that if we suddenly start adding the site name to WP_title by default, 9 out of 10 themes break.

            Then don’t? Leave wp_title() output as is. Give mild customization in core or just point to plugin.

            > We wanted 1 new function that takes care of the entire title.

            wp_title() can take care of this already, can’t it?

          • Joost de ValkBy Joost de Valk on 5 September, 2011

            read that trac ticket for more, I’m afraid that indeed, you don’t get it :-)

          • RarstBy Rarst on 5 September, 2011

            I did read it. :)

            I just see this is a problem with coding practice, not a problem with code. Do you disagree?

            I think first step to addressing it would be to edit Codex (that happily teaches people how to implement hardcoded mess in titles) and fix Twenty Eleven (still don’t get why using filter was rolled back there).

            Otherwise people will just swap old template tag for new template tag. In the middle of hardcoded mess. No?

          • Joost de ValkBy Joost de Valk on 5 September, 2011

            No. It’s harder to change current coding styles than to implement new functionality. Also, the core issue is and remains without this patch; that part of the content will be generated by the template, which is simply not an option.

  3. George CoghillBy George Coghill on 5 September, 2011

    Completely agree here, the way WordPress defaults to the display of titles is very poor and to be honest even the need for your Yoast SEO plugin section for manipulating titles should be eliminated by incorporating them into WordPress. At the least in an advanced options manner or similar.

    With meta titles & descriptions playing such a huge role in whether your site makes it into a worthwhile place in Google’s search results, it’s pretty frustrating to have to rely on workaround for something that it the focus of my (and many others’) SEO efforts.

  4. IliaBy Ilia on 5 September, 2011

    I’m a bit confused about this. Your SEO plugin allows us to do exactly that – customize title as we see fit on a per-page basis, and that’s without “force rewrite”. And I figured every good SEO plugin has that capability.

    So why do we need a different solution? Or are you just saying that by default WP should allow control like that?

    • RarstBy Rarst on 5 September, 2011

      The SEO plugins allow to do that reliably when only wp_title() is used to generate title tag and so all of it can be filtered.

      But Codex and native theme currently encourage to add more things in template file (instead of using filter). So themes put extra stuff in title tag, that cannot be filtered and can only be dealt with via inconvenient output buffering.

  5. Chuck ReynoldsBy Chuck Reynolds on 7 September, 2011

    I’m all for that… they need a Yoast cleaning up some of that core stuff

  6. Andrew GroatBy Andrew Groat on 7 September, 2011

    I think I distinctly remember facepalming myself when I saw that in the header.php of TwentyEleven. Can’t see the logic in replacing wp_title()… complicated < simple.

    Completely agree with you that this needs to be addressed.

  7. Seth StevensonBy Seth Stevenson on 7 September, 2011

    I have though WP’s title function has been lacking for a while. For bigger sites I run with pages and sub-pages and sub-sub-pages often I want to include the parent pages title.

    What if you could register a function for each post_type in functions.php that controls that post_type’s title? If nothing is defined for the post_type being displayed then it uses the default title function.

  8. folkgrapheinBy folkgraphein on 7 September, 2011

    we have to think about it. No lacks will be excepted if there will a good concept or semantic way……….

  9. Katinka HesselinkBy Katinka Hesselink on 7 September, 2011

    While the default way titles are displayed in 2011 is fine by me, I agree that the importance of titles in SEO is such that it should be easy to code for something different.

    While you’re all at it- please include an easy (and default) way to deal with title tags for tag pages and category pages as well.

  10. JyleBy Jyle on 7 September, 2011

    I’ve always used Yoasts SEO plugin since i knew of it, and have always manually changed the code. Now i know why and im glad i have been. Another reason why the plugin is kickass :)

  11. KarenBy Karen on 7 September, 2011

    Just came across your plugin. Now testing it out. A bit confused by all the discussions going on though. Think I won’t check the ‘force rewrite’ until I understand better. Just subscribe to your newsletter. Thanks.

  12. UmbrovskisBy Umbrovskis on 8 September, 2011

    Just like some others here, I use Yoast’s SEO plugin, but before that I had similar function that “hijacked” title tag (wp_title()) and made modified output. Now using mine as backup function in my WordPress themes if client uninstall (my mistake on curiosity).
    And yes, by default I delete or/and not using default WordPress title output.

    New title output tag would be nice.

  13. Leonard GrossamanBy Leonard Grossaman on 10 September, 2011

    I just discovered a related problem last night preparing my latest post. The SEO analyzer in your SEO app kept making a destinction between the article title and the page title and telling me that my keyword wasn’t in the title.

    I recognize that the nature of my site doesn’t let me organize content in ways that good SEO might prefer, but I do try to at least select key words that appear in the selected fields. It would be nice if the editor had a field for page title as well as the article heading.. even if they are identical. My typing is too erratic to risk going behind the editor and hand carving. Trudel’s Truth

  14. Trisha CupraBy Trisha Cupra on 11 September, 2011

    I don’t know why Yoast’s SEO plugin hasn’t become core functionality yet. I don’t consider a WordPress site complete without it. (I recently showed a client how the SEO plugin works, in person, and she practically danced around the room with joy.)

  15. JavierBy Javier on 21 September, 2011

    I use WordPress SEO by Yoast, but on categories with parent category, title only show simple category. What can i do to show as this: Parent_Category – Child_Category


  16. klaasBy klaas on 25 September, 2011

    Hi i have some things to ask
    webiste is tnx invitation code

    In your plugin i go to seo -titles-homepage
    fil in myn title and description and keywoords

    - 1 how can i remove the date (26 Jul 2011 –) before mijn
    in the google results 26 Jul 2011 –
    whas thinking that wil be remove by mijn description

    - 2 when i look in mijn pagesourc i see this
    Tnx invitation code 2011 valid and FREE tnx INVITATION CODE here |

    why is ther a | in mijn title

    -3 google change my titel is this the plugin or just google and do y know why
    mijn title in google whas
    Tnx invitation code 2011 valid and FREE tnx INVITATION CODE here |
    and when i look now in google i see title Tnx invitation code

    and i look to In your plugin i go to seo -titles-homepage
    but that is stil all the same.

    so hope y can help me