“What’s SEO?” I hear you saying. It stands for Search Engine Optimisation and is the term given to the art of making your site more “search engine friendly”.

There are a number of ways of doing this and most of them can be placed under a heading of “Cheating”. I won’t bother discussing those here as many of the search engine bots are getting clever and ignoring them. Instead I will describe 2 methods which can both be used together and which are not “cheating”.

They use an identical method but one is used for the <title> tag in the <head> of your page and the other is used as an “off-screen” <h1> tag within the <body> of your page. They both use native TXP tags.

Many people might not be aware of this, but you can use TXP tags in the <head> section. This means that you can have both a dynamic <title> and a dynamic <h1> tag.

Here’s some code:-

<title><txp:if_individual_article> <txp:section title="1" />: <txp:page_title /> <txp:else /> <txp:section title="1" />: <txp:site_name /> </txp:if_individual_article></title>

This replaces the standard <title> tags and first asks if we are looking at an individual_article page. If we are, it outputs the section title, followed by a colon, then the <txp:page_title /> tag adds the site name followed by a colon followed by the article’s title, so for this page, if you were looking at the individual_article view ie you can see the comments and/or comment entry form, the <title> tag would say:-

Textpattern Coding: The Bomb Site: TXP and SEO

However if we are viewing an article_list, such as the front-page it will output:-

Home Page: The Bomb Site or
Articles: The Bomb Site or
Textpattern Coding: The Bomb Site

depending on which section is being viewed.

Exactly the same code can be used for the <h1> tag by simply removing the <title> tags in the above code and wrapping it with <h1> tags, so you would have:-

<h1><txp:if_individual_article> <txp:section title="1" />: <txp:page_title /> <txp:else /> <txp:section title="1" />: <txp:site_name /> </txp:if_individual_article></h1>

The outputs are identical to the above except you now have an <h1> which needs placing somewhere near the top of your code in the <body> of the page, in fact preferably it should be the first item. This isn’t actually going to appear “on-screen”. If you have used an <h1> for your site name then change it to something else like an <h2>. You DO NOT want two <h1> tags on the same page.

As I said, your new <h1> should not appear “on-screen” so you need some CSS to make this happen:-

h1 { height:1px; text-indent:-500em; }

So what does that do? Well first it gives it a height of 1px. Don’t try and be clever and use 0px as it will cause problems in certain browsers. The next parameter – “text-indent:-500em;” – throws the <h1> tag 500ems to the left which should place it a few feet to the left of your screen so that it will not be visible though it will still appear on the page for certain types of browser that do not use the CSS like screen-readers.

Now all this just gives you the basic idea of how to create dynamic <h1> and <title> tags but you should remember that you can use any TXP tags that you want in order to provide the information you want to appear in whatever order you require it.

If you surf around the bombsite you will see that I have a more complex <title> tag at work which is identical to my <h1> tag. It uses the following code:-

<txp:if_article_list> <txp:if_category><txp:category title="1" /> category listing. &raquo; <txp:site_name /> <txp:else /> <txp:if_section name="default">Home Page<txp:else /><txp:section title="1" /></txp:if_section> &raquo; <txp:site_name /></txp:if_category> </txp:if_article_list> <txp:if_individual_article><txp:title /> &raquo; <txp:section title="1" /> &raquo; <txp:site_name /></txp:if_individual_article>

As you can see this is a little more complex than the examples shown above and it does some weird and wonderful things which I won’t explain as it would take too long. Just wander around the site a bit, click on article titles or categories and see what you get.

You should look at other SEO methods besides this to get optimum results.

TXP r2392 changes the <txp:sitename /> tag to <txp:site_name /> and r2647 introduces a new notice for deprecated tags so if you are using a Textpattern version below r2392 you should modify the above code to use the old version of the tag but an even better idea would be to upgrade.

Comments [9]