In the first article on TXP and SEO I discussed the use of a form containing textpattern tags to create dynamic <title> and <h1> tags. I’m now going to discuss the use of forms to create dynamic <meta description /> and <meta keywords /> tags but before I do that let me quickly mention the use of sitemaps specifically designed for Google.
Google Sitemaps
Using a sitemap helps Google to index your site and can contain only those parts of your site that you want indexing. With the sitemap in place you can also use the on-line Google tools to see how each page ranks, is searched, is visited and is linked to from external sites. This can give you some quite useful information and how you use it is up to you. You will need a Google account and you will need to login to Google Webmaster Tools. You will also need to create your sitemap and the simplest method I’ve found for this is Jukka’s rah_sitemap plug-in. It’s so simple I shan’t go through the set-up here and once it is in place you just add the sitemap URL to your Webmaster Tools page and leave Google to get on with it.
The <meta /> tags.
This method will simply use forms which are called to the <head> section of the page template using the <txp:output_form form=“formName” /> tag. There are some plug-ins out there that will do the job for you but I prefer this method as it allows me to control the output more closely. I get what I want and not something that a plug-in allows me to have and I don’t need to use any “custom_fields”.
A couple of things to remember. Both <txp:title /> and <txp:keywords /> are “article” tags and will only display their contents when you are viewing the site in “individual_article” mode. In other words if you are viewing, say, a section front-page which is an “article_list” view these 2 tags will display blanks.
Also Google seems to place more emphasis on the “description” tag than the “keywords” tag to the point where I’m not sure if using the “keywords” tag is worth the effort. This is probably due in no small part to the “cheating” tactics used by many websites trying to stuff as many keywords in as are contained in the O.E.D. If you do decide to use the “keywords” tag please do so with a lot of consideration otherwise it’s use could be detrimental to your site rather than an asset.
The <meta description /> tag
For the <meta description /> tag at The Bombsite I am using a form called “meta_description” and it looks something like this:-
<txp:if_section name="default"><meta name="description" content="My Textpattern experiences, Textpattern code and Textpattern themes (styles, templates) plus a blog about anything that catches my attention." /></txp:if_section><txp:if_section name="about,archivescat,contact,links,privacy,resume"><meta name="description" content="The Bombsite - <txp:section title="1" />." /></txp:if_section><txp:if_section name="articles"><txp:if_article_list><meta name="description" content="My weblog about anything that catches my attention." /><txp:else /><meta name="description" content="<txp:title />." /></txp:if_article_list></txp:if_section><txp:if_section name="textpattern-coding"><txp:if_article_list><meta name="description" content="Textpattern code examples." /><txp:else /><meta name="description" content="Textpattern code examples - <txp:title />." /></txp:if_article_list></txp:if_section><txp:if_section name="textpattern-themes"><txp:if_article_list><meta name="description" content="Textpattern themes, Textpattern styles, Textpattern templates." /><txp:else /><meta name="description" content="<txp:title /> - a theme for Textpattern." /></txp:if_article_list></txp:if_section>
and as you can see it is a continuous line of code which removes any blank lines that might appear in the source code of the page but isn’t much use here, so here is the same code with line breaks in it to make it more understandable:-
<txp:if_section name="default">
<meta name="description" content="My Textpattern experiences, Textpattern code and Textpattern themes (styles, templates) plus a blog about anything that catches my attention." />
</txp:if_section>
<txp:if_section name="about,archivescat,contact,links,privacy,resume">
<meta name="description" content="The Bombsite - <txp:section title="1" />." />
</txp:if_section>
<txp:if_section name="articles">
<txp:if_article_list>
<meta name="description" content="My weblog about anything that catches my attention." />
<txp:else />
<meta name="description" content="<txp:title />." />
</txp:if_article_list>
</txp:if_section>
<txp:if_section name="textpattern-coding">
<txp:if_article_list>
<meta name="description" content="Textpattern code examples." />
<txp:else />
<meta name="description" content="Textpattern code examples - <txp:title />." />
</txp:if_article_list>
</txp:if_section>
<txp:if_section name="textpattern-themes">
<txp:if_article_list><meta name="description" content="Textpattern themes, Textpattern styles, Textpattern templates." />
<txp:else />
<meta name="description" content="<txp:title /> - a theme for Textpattern." />
</txp:if_article_list>
</txp:if_section>
It is called into the <head> section of the page template using <txp:output_form form=“meta_description” />. As you can now see this is quite a complex form using many “conditionals” in order to output exactly what I want on the various pages of the site. Whilst it is complex it is something that can be gradually built-up over time so just get the basics right first then slowly modify it to bring in other bits and pieces until you get to the final result that you want. Take your time. Get it right. This isn’t something that needs to be rushed.
So how does it work?
The first block asks if we are in the “default” section which is the front-page of The Bombsite. As this is the “entry” page it has a general description for the whole site.
The second block asks if we are in one of several smaller sections which are fairly content specific so all I show there is the site name followed by the section title. Very simple.
The third block is a little more complex and first asks if we are in the “articles” section and if we are it then asks if we are in “article_list” view and outputs a general description for that section but if we are in “individual_article” view (<txp:else />) it will output the title of the article being viewed.
The next 2 blocks do much the same as the third block but for the “Textpattern Coding” and “Textpattern Themes” sections, outputting different descriptions dependent on whether we are in “article_list” or “individual_article” view.
I’m not using them myself at the moment but you could also add <txp:if_category> coditional tags if you want to add descriptions specific to categories.
The <meta keywords /> tag
As I mentioned earlier, I’m not really sure if the <meta keywords /> tag is worth too much effort as Google doesn’t seem to give it much weight plus the possible downside to being over-zealous with your use of keywords. I don’t use the tag at The Bombsite at the moment, instead I add any keywords to the end of the <meta description /> tag when in “individual_article” view however you could use a form similar to the following:-
<txp:if_individual_article>
<meta name="keywords" content="<txp:keywords />" />
</txp:if_individual_article>
Now as I also mentioned earlier the <txp:keywords /> tag can only be used when we are in “individual_article” view so in order not to have an empty tag on lots of pages we start with the <txp:if_individual_article> tag. This surrounds the <meta> tag which uses the <txp:keywords /> tag as a value for “content”. This is probably the simplest form you could use.
Now for each article, whilst in the “Write” tab, if you click on “Advanced Options” you will see a text box called “Keywords”. Just type your keywords into this box as a comma-separated list. The Textpattern tag will pick these up and use them as the value for “content”.
Just as with the code for the description tag, you can add other conditionals such as <txp:if_section> and <txp:if_category> so that you can be specific about where keywords are used and where not. Don’t forget to remove the “line-breaks” in the code to keep white-space in the source code to a minimum.
Oh! If you didn’t get the message before, please be VERY CAREFUL with this tag!



Gocom
15 November 2008 at 02:38 AM
Nice that you like rah_sitemap :-) I want to thank you Stuart for reporting all those rah_sitemap’s “missing” things :)