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:


<?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";
?>
	

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.


<?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";	
       } 
?>

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


More like this:


Posted in: SEO, WordPress
TAGS:, , , , , , , , , , , , , , ,
Both comments and trackbacks are currently closed.

13 Comments

  1. Aug 18th, 2012 9:56 PM

    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. Aug 3rd, 2012 7:48 AM

    Very interesting SEO techniques. Thanks for sharing it

  3. May 17th, 2012 9:51 PM

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

  4. Apr 1st, 2011 4:57 AM

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

  5. Jan 20th, 2011 9:02 AM

    Great share...will be usefull for seo beginners

  6. Dec 28th, 2010 3:51 PM

    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. Dec 20th, 2010 4:41 AM

    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. Dec 14th, 2010 8:58 AM

    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. Dec 5th, 2010 2:42 PM

    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;
    }
    • Dec 5th, 2010 3:22 PM

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

      • Dec 5th, 2010 3:58 PM

        Yeah, for that you can use the wp_title filter.

        • Dec 6th, 2010 1:43 AM

          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. Dec 4th, 2010 4:44 PM

    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! :)