How to add SEO titles without plugins


Purpose of this article is to demonstrate a simple technique for having separate, "SEO titles" for your posts. Normally article title is copied into the browser title plus usually the blog name. What we want is to have a simple way of specifying the browser title for our specific article and we do not want any fancy SEO plugins to do it.

Your current title structure in header.php of your theme might look something like this:

<title>
<?php 
        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";
?>
</title>

What we want to achieve is to use a custom field which we will call 'seotitle' and whenever you specify this custom field in your post we want to use the text you entered as our browser title. In order to do this we need to modify the above code so it checks for this custom field and uses it instead.

<title>
<?php 
global $post;
 
if (is_singular() && ($title=get_post_meta($post->ID, 'seotitle', true)))
       echo $title;
else { 		
	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";	
       } 
?>
</title>

And that's all basically, from now on you can specify the browser title in the custom field.


Suggested reading:


Posted in: SEO, WordPress
TAGS:, , , , , , , , , , , , , , ,
leave a comment.

Comments:

13 Comments

  1. online marketing consulting services
    Aug 18th, 2012

    I had no clue about this technique, I always used to update the tags with the help of plug-ins. Thanks a lot for sharing this with us

  2. SEO Toronto
    Aug 3rd, 2012

    Very interesting SEO techniques. Thanks for sharing it

  3. Philipp
    May 17th, 2012

    Nice. This helped me a lot. Thanks for sharing!

  4. Kilovars
    Apr 1st, 2011

    Wow! Thanks a lot for all that good information. I really appreciate it.

  5. Chennaimoms
    Jan 20th, 2011

    Great share...will be usefull for seo beginners

  6. CJ
    Dec 28th, 2010

    I have just started using WordPress for websites (as opposed to just a blog), and was looking into SEO issues like titles and meta tags. I am still trying to get a good grasp on it all, but shouldn't the custom field be named 'seotitle' in your example?

    Thank you for sharing your knowledge!

  7. Sherman Unkefer
    Dec 20th, 2010

    Excellent tip thank you very much. I will have to incorporate this technique into my site as well. I have bookmarked your site and will definitely be returning.

  8. rangjai
    Dec 14th, 2010

    Vladimir, it works on Home, Pages, Single pages, Archives, and Categories. But it won't work on frontpage paging. I need page title on title bar for the usability reason. Do you have any idea?

  9. Kaspars
    Dec 5th, 2010

    It is better to use the single_post_title filter instead. Something like this in functions.php:

    add_filter('single_post_title',  'custom_post_title');
    
    function custom_post_title($title) {
    	global $post;
    	
    	if ($custom_title = get_post_meta($post->ID, 'title', true))
    		return $custom_title;
    
    	return $title;
    }
    • Vladimir
      Dec 5th, 2010

      The approach would not allow for total control over the title as blogname for example would be automatically added in most cases.

      • Kaspars
        Dec 5th, 2010

        Yeah, for that you can use the wp_title filter.

        • Vladimir
          Dec 6th, 2010

          That would not help either, as people often have title structure set as in my example )which is more or less coped from the twenty ten theme). The only way to have a proper SEO title control is the one in the example (although maybe not the most elegant)

  10. Nabil
    Dec 4th, 2010

    I had no idea one could do this like that. Thanks for the tip, Vlad. And keep up the good work with all them plugins! :)

Have your say

Your email is never published nor shared. Required fields are marked *

*
*

Subscribe without commenting

About

vladimir prelovac Vladimir Prelovac is CEO of Prelovac Media, a computer engineer by profession and an adventurer by state of mind. more +


"I would love to change the world, I just don't have the source code yet."

Services

Manage multiple WordPress sites

Built for WordPress enthusiasts, ManageWP helps you manage all your WordPress sites from one central location.

Books

WordPress Plugin Devleopment Book Read my book WordPress Plugin Development: Beginner's Guide

Published by Packt Publishing, available online through Amazon.