WordPress SEO - Page Titles and Meta Tags
The plugins involved are Optimal Title from Aaron Schaefer, and Jerome’s Keywords from Jerome Lavigne.
The challenge
Your webpage titles (contained in the<title> ... </title> html tag) should be descriptive of the page content and contain the important keywords you hope to be found for when people search at Google, Yahoo! or other search engines. It’s also generally accepted that adding the Meta tags for Keywords and Description will usually help search engine spiders/robots when indexing your pages, though there are no standard rules for which search engine cares about (if they use them at all) which, and how much importance they place on those page elements. I like to include them everywhere since it doesn’t take much time and can’t hurt.
WordPress’s default style for titling your posts is to have the Blog name first followed by the Post or Page title. Unfortunately, the important keywords are in the title of your posts so the title needs to be up front. The Optimal Title plugin takes care of reversing the default naming scheme and is an easy modification to your theme’s header template. Here’s an example from my theme’s header.php file:
<title><?php optimal_title('»'); ?></title>
Pass Optimal Title a character or string to use in separating the name of the Post from the blog name. Now instead of:
Wayne’s Fabulous Blog » WordPress SEO
the page title becomes:
WordPress SEO » Wayne’s Fabulous Blog
Adding Meta Keywords and Descriptions
Jerome’s Keywords plugin ads a field to WordPress editing form for you to enter your custome keywords to a post. As long as you get into the habit of entering this extra information, you can make them appear on each Post’s page in the <meta name=”keywords” content=”…” /> header tag. The plug-in provides a variety of PHP functions for getting a post’s keywords and also automatically ads the proper Technorati tags to your Atom feeds (normally Technorati only indexes the categories of a post).
Unfortunately, Jerome’s Keywords plugin doesn’t support adding the Meta description tag. This to me is more important than keywords and if you’re in the habit of providing explicit excerpts to your posts (you need to use Advanced Edit Mode when writing your posts), you basically have a good description ready for placement in your headers. To remedy this and avoid having to use a separate plugin just for Meta descriptions, I modified Jerome’s Keywords last weekend to include the following new function:
get_the_description($format_with_tag,$default_desc)
if $format_with_tag = true, it creates the <meta name=”description” content=”…” /> with your post’s description, and you can specify a string as the second parameter which is used if a more specific description cannot be found. The logic for locating a description for any given page roughly follows these rules:
- If it’s a Single (post) or Page being served, look first for the custom description field, if not found look for an Excerpt, and finally use the default string passed in if any.
- If it’s the home page use any default string passed in, or if none provided, use the blog description
- If it’s a category page, it will first use the default you pass it, or if none is provided it resorts to constructing a description from the category description (because of this I have gone back and rewritten all my category descriptions).
In addition to this, in my header template I check to see if we’re loading a page from a local search and in the case construct a description using the search text.
Finally, here’s the code I include into my header template file to handle setting the Title, and Meta Keywords and Description:
1 <?php
2 /* this file is included in the header file using the syntax:
3 * <?php include (TEMPLATEPATH . '/header_stuff.php'); ?>.
4 */
5 $DEFAULT_DESC = (empty($DEFAULT_DESC) ? 'Your Blog Description Here' : $DEFAULT_DESC);
6 ?>
7 <title><?php if(function_exists('optimal_title')) : optimal_title('»'); endif;?><?php bloginfo('name'); ?></title>
8 <?php if( function_exists('get_the_keywords') ) :
9 $myKeywords = get_the_keywords('','',',',false);
10 ?>
11 <meta name="keywords" content="<?php echo $myKeywords; ?>" />
12 <?php endif; ?>
13 <?php if( is_home() ) :
14 // set static blog description on home page
15 $metadesc = $DEFAULT_DESC;
16 elseif (!empty($_REQUEST['s']) ) :
17 // results of a search so fabricate a good description
18 $metadesc = "Read articles about " .$_REQUEST['s']. " and find information related to " . $_REQUEST['s'];
19 elseif ( function_exists('get_the_description') ) :
20 // use modified Jerome's Plugin to get an intelligent description from
21 // custom keyword or the excerpt
22 $metadesc = get_the_description(false,$metadesc);
23 else: $metadesc='';
24 endif; ?>
25 <?php if( ! empty($metadesc) ): ?>
26 <meta name="description" content="<?php echo $metadesc; ?>" />
27 <?php endif; ?>
So whether you want to get as detailed as I have, or simply switch to using the Optimal Title plugin to make your titles more search engine-friendly, sooner or later you will need to consider how well your pages work for SEO if you care about your blog/website being found by your public.



October 7th, 2005 at 3:00 pm
Hi - I would like to try this, it looks very good. Not being a php expert I have a question :)
You say “I modified Jerome’s Keywords last weekend to include the following new function: get_the_description($format_with_tag,$default_desc)”
Where does that line go? Are there any other modifications I have to do?
Thank you. - Roger
October 7th, 2005 at 7:15 pm
RS,
I’ll email you the plugin. PLEASE(!) do not bug Jerome about it. I’ve sent him the modifications and I’m giving him ample time to decide if he wants to incorporate some of them before I consider releasing it myself. He’s been responsive to past suggestions and comments from me, But he may not have the time now or inclination to merge those features.
Another thing, Make certain you disable or remove his version of the plugin before installing my hacked version. It can’t be good having both activated, though likely wouldn’t harm anything.
Re: your question: let’s keep things simple in the first pass.
My plugin mods will give you a new field in the Advanced editing mode of WordPress for entering a Description. However, it’s better to just use the Excerpt field since WP templates make use of that, and my plugin will use that if the custom "Description" field is empty. So get in the habit of using the Excerpt field (a future update will probably add support for auto-generating excerpts).
Next, in your Template’s header file, you’ll insert the PHP code. I recommend using one of the two lines in place of any meta-description tag you may presently have there:
<?php get_the_description(TRUE, ‘my page description’); ?>
or
<?php get_the_description(TRUE); ?>
This code must be placed inside the <head> section of your page template.
October 8th, 2005 at 8:42 am
Thank you very much Wayne! I seem to have got it all working and will test it out over the next few weeks. - Roger
PS I had to use rather than for some reason.
October 9th, 2005 at 7:56 pm
Roger, you should have received the plugin by email (unless it bounced back to me and I haven’t seen the bounce yet). Your WordPress theme most likely has a file called header.php. Open that for editing and just under the <title>…</title> tag, add that function call.
Make sure you’ve enabled the modified Jerome’s Keywords before adding that code to your header file. Otherwise (depending on the PHP settings) you’ll get errors in your page since the function will not exist.
October 10th, 2005 at 9:07 am
Hi - Thanks for the fantastic technique using the existing plugins.
Where do we need to put this header_stuff.php created with the stuff above. In which place I need to include the header_stuff.php in my existing theme header template. Do I need to replace everyting inside the ‘header’ tags.
October 10th, 2005 at 5:47 pm
chandu,
I would start simple and just get pieces of this stuff working first without worrying about putting it all in a separate file the way I have. However, I’ll start by mentioning that technique. My external php file header_stuff.php is responsible for setting my page title and the two meta tags for keywords and descriptions.
If you place header_stuff.php inside your active theme directory, you include it like this:
<?php include (TEMPLATEPATH . ‘/header_stuff.php’); ?>
if you want to put it one level above into the wp-content/themes directory, use this:
<?php include (TEMPLATEPATH . ‘/../header_stuff.php’); ?>
First step, get Optimal Title working. Make sure you’ve installed the plugin and activated it, then replace the code in your Header.php file which outputs your page title with this code:
<title><?php optimal_title(’»’) . bloginfo(’name’); ?></title>
Then you can add the meta keywords using Jerome’s plugin:
<meta name=”keywords” content=”<?php echo get_the_keywords('’,'’,',’,false); ?>” />
The description you’ll have to figure out on your own I guess since Jerome hasn’t added that feature to the plugin yet. But I think you can use
the_excerpt();to ask WordPress for a post’s excerpt (when you’re on a page or post — single — page). So probably you’d put inside your meta description tag’s content= property, something like this:<?php the_excerpt(); >
see WordPress Codex, the_template tag for more info on using that template tag.
-wayne
October 11th, 2005 at 1:16 am
Wayne -
Yes thanks Wayne all received and implemented.
I did not use Optimal Title because I do not believe that including the name of the site in every on every page of the site is good SEO. I have replaced in the theme header with this which uses the name of the site in the title only on the home page and uses the post title everywhere else. Much better for SEO!
Coupled with your script modifications Wayne this is the best SEO of wordpress headers possible - Thank you!
- Roger
October 11th, 2005 at 1:18 am
Wayne -
My code lines seem to get edited out of my posts. If you tell me how to avoid this I will repost.
- Roger
October 13th, 2005 at 12:58 am
Well, I guess you may need to escape the html tags. e.g., < becomes <, > becomes >. Otherwise, just email me.
March 15th, 2006 at 9:04 pm
So where is the plugin??? What you describe looks exactly what is needed for a client