Customized Title Optimization – WordPress Plugin Alternative

A typical title in the standard (Kubrick) WordPress theme looks like:

Blog name » Title of Post

Unless you explicitly like to brand your blog name, that’s not a search engine friendly title.

I’d rather have the title of the post as my page title.
As an option, it could be followed by the blogname, so that branding still takes place, but personally I prefer not to include that.

There are WordPress Plugins that will do the trick. And many are added frequently. If you prefer the plugin-route, just do a search on WordPress Plugin Meta or visit WordPress or WordPress Plugin Database.

When I started blogging, these plugins weren’t available, so I created my own title optimization alternative.
And I still use it today. I’m very happy with it, because I’m in control and don’t need yet another pluging (have so many already).

Here’s how it works.

In the theme directory find the file called header.php.
In there, find this line:

<title><?php bloginfo(‘name’); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>

and replace that by:

<title><?php $title = wp_title( ”, false ); if (!$title) {bloginfo(‘name’); } else {wp_title();} ?></title>

This line of code simply says, that if there isn’t a post title, it should display the blogname, otherwise the title.

Now, the standard WordPress theme doesn’t include description and keyword Meta Tags.
We can easily add these right below the line we just pasted in:

<meta name=”description” content=”<?= bloginfo(‘name’)?> presents <?php $title = wp_title( ”, false ); if ($title) {wp_title(); echo ” “;} ?>and other xxxx topics. ” />
<meta name=”keywords” content=”<?php $title = wp_title( ”, false ); if ($title) {wp_title(); echo “, “;} ?>xxxx” />

Replace xxxx by your main keyword. Upload header.php and your Meta Tags will exactly fit the title of your post.

Easy uh?

Unfortunately WordPress inserts a » (right angled quote) before every title and I don’t like it. To delete that, you have to find the general-template.php file under wp-includes.

In that page, find function wp_title($sep = ‘&raquo;’, $display = true)
In that function, find these two lines:

if ( !empty($title) )
$prefix = ” $sep “;

and comment them like this:
// if ( !empty($title) )
// $prefix = ” $sep “;

Upload the file again and the right angle quote is gone.

Done, in less than 5 minutes!

Special Note: when upgrading your WordPress version, don’t forget to save the WordPress theme folder (and the general-template.php file under wp-includes) and upload it again after upgrading.

That’s how I customize my WordPress titles and, on the fly, the description and keyword meta tags.
Your thoughts?




Share this post using these icons:
Facebooktwittergoogle_pluslinkedinmail

Related Posts

 

Comments are closed.