TwentyEleven’s TITLE tags make Yoast’s work harder.

written by William Patton on October 8, 2012 in WordPress Custom with 2 comments

TwentyEleven – a default too far.

Time is upon us for a new WordPress default theme to take over from the much loved TwentyEleven. I use TwentyEleven it myself on a few sites and above the fact that it’s default there are a few other reasons that people stick with it but first let’s talk about the new default – TwentyTwelve. It’s there right now in the WordPress theme repo for you to download and use and it will come bundled with WordPress 3.5 in the coming days/weeks. It’s been a long time coming considering it’s now October and if you notice the naming pattern: TwentyTen – 2010; TwentyEleven – 2011 and TwentyTwelve – 2012 then the latest edition should have been available for a while now.

English: The logo of the blogging software Wor...

English: The logo of the blogging software WordPress. Deutsch: WordPress Logo 中文: WordPress Logo (Photo credit: Wikipedia)

However it’s available now and that’s good enough for me. The main website I have TwentyEleven on is Gaming Now and I will be spending the next few days getting that site into good shape for the upgrade to TwentyTwelve.

TwentyEleven – Title Tags are a nuisance

When I was looking at my customized version of TwentyEleven to try recall the theme changes I had made . I hadn’t made it easy on myself – it was pretty difficult considering I had made a child theme but neglected to make all the changes through the child theme! Now I need to spend the next few days collating the changes made through both the parent and child themes.

One of the major things I noticed when looking at my changes was that Yoast’s “WordPress SEO” plugin couldn’t rewrite my site’s Titles due to the way that TwentyEleven had gone about setting up it’s default titles. The default titles weren’t bad as such but I like to have control over them on a page-by-page basis – Joost De Valk made that possible with WordPress SEO but I found that it didn’t quite work right for me.

What happened when I tried to rewrite the titles.

My re-written title would appear first but then it would immediately be followed by the site title without a separator or space between it: pages were doing even funnier things with my homepage title being – “Gaming Now|Home – Where I get my news, now where you do too|Gaming NowGamingNow”. That’s including the page title, site tagline and the site name multiple times. Disregard the fact that it looks a mess there are other, more serious, implications of a site title like that – especially my homepage. Numerous basic SEO rules are broken; a page title should describe the page content, at least in part; it should be readable, which it isn’t really and it should try to capture the reader’s interest.

Those were major concerns that I had to deal with ASAP and the fix was really easy so I had no excuse not to get around to it.

How to fix TwentyEleven’s <Title> tag to work with Yoast’s WordPress SEO Plugin

The WordPress SEO plugin uses the wp_head tag to print it’s titles into the page mark-up. TwentyEleven does have this tag but it’s mixed up with other pieces of code to make it’s default titles work as well as can be. I didn’t want to remove that feature completely so instead I used a conditional statement. In essence I said to it that if WordPress SEO is active then you should use the code that contains only the tag that the plugin uses but if WordPress SEO isn’t active then use the default code that existed in the theme originally.

It was easy as adding the conditional statement. I’ll paste the whole lot of the code I used here for reference or in case you wanted to use it yourself. I have used the WPSEO_VERSION constant because it was the first one that came to my mind but you could also just have done an ‘is_active’ on the plug-in too, both methods will work just as well as each other, similarly you could use any other constant or method that WordPress SEO defines.

// Detect Yoast SEO Plugin
if (defined('WPSEO_VERSION')) {
} else {
* 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', 'skeleton' ), max( $paged, $page ) );