TXP and SEO
“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> element 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>. This means that you can have both a dynamic <title> element 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> element 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> element would say:-
Textpattern Coding: The Bombsite: TXP and SEO
However if we are viewing an “article list”, such as the front-page it will output:-
Home Page: The Bombsite or
Articles: The Bombsite or
Textpattern Coding: The Bombsite
depending on which section is being viewed.
Exactly the same code can be used for the <h1> tag by simply removing the <title></title> tags in the above code and wrapping it with <h1></h1> tags instead, 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 CSS like screen-readers.
Now all this just gives you the basic idea of how to create a dynamic <h1> tag and <title> element 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> element 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. » <txp:site_name />
<txp:else />
<txp:if_section name="default">Home Page<txp:else /><txp:section title="1" /></txp:if_section> » <txp:site_name /></txp:if_category>
</txp:if_article_list>
<txp:if_individual_article><txp:title /> » <txp:section title="1" /> » <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 changed the <txp:sitename /> tag to <txp:site_name /> and r2647 introduced 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 in truth, what you really need to do is upgrade.
Thanks for this article.
The home page will show as “default – site name”, which is kind of ugly. Do you have a suggestion for making “default” not appear?
It’d be nice to be able to remove the site name from the page title. For SEO, the site name probably shouldn’t in the title or the H1 tag. Txp’s default page_title will usually include the site name. Any ideas on how to do this? I got stuck when Txp wouldn’t allow nested conditionals.
Well mine shows as “Home”. Are you on an older version?
Anyway you can add a conditional:-
<txp:if_individual_article>
<txp:if_section name=”,default”>
Home: <txp:page_title />
<txp:else />
<txp:section title=“1” />: <txp:page_title />
</txp:if_section>
<txp:else />
etc.
As far as I am aware, having the site name in the title or H1 is not detrimental. I’ve certainly not had any problem with it and I don’t know a way of removing it unless you hack the base code in some way.
But what I want is to put the article title first then the site title. I see no way of doing that…
Tim, just change the position of the Txp tags. See my example in this thread .
Maybe you can’t tell from that link I just gave. This is what I have on my site:
<title>
<txp:if_section name=”,blog”>
<txp:if_individual_article>
<txp:title /> | <txp:sitename />
</txp:if_individual_article>
<txp:if_article_list>
<txp:sitename />: <txp:site_slogan />
</txp:if_article_list>
<txp:else />
<txp:if_individual_article>
<txp:section /> » <txp:title /> | <txp:sitename />
</txp:if_individual_article>
<txp:if_article_list>
<txp:section /> | <txp:sitename />
</txp:if_article_list>
</txp:if_section>
</title>
I’ve used the SEO code above and it works. But I have one small problem: The text from the except field appears with the open and close para tags (i.e. <The except text of my blook here</>) in my title bar at the top of the browser window. Do you know they cure?
Can you email the code you are using across to me? Use the Contact form.
Here it is…
<!— head —>
<div id=“head”>
<h1><txp:if_individual_article> <txp:section title=“1” />: <txp:page_title /> <txp:else /> <txp:section title=“1” />: <txp:sitename /> </txp:if_individual_article></h1>
<!— left —>
Having checked your site the problem isn’t with your “h1” tag, it’s with the “title” tag in the “head” section and only when in individual_article view so I would need to see the code you are using for the “title” tag.
is the order of title tags important meaning SEO? i mean if a article title is in first place not last, gives a better search ranking?
Hi Gallex.
Yes. If you look at the last piece of sample code which is what I use here you will see that it includes the “txp:if_individual_article” tags and within those I place the article title first, then the section title and the site name last. You should be able to see how both the “title” and “H1” tags appear on the bombsite at the top of your browser window or in the browser tabs if you have them.
Don’t forget that you should also look into meta tags, particularly meta description. I use a form for that and I may do an article on it.
very good! only one thing: i don’t want text Home Page >> to homepage title, just sitename
can’t wait. at the moment i’m using this solution
if i just remove “Home Page” from there:
<txp:if_section name=“default”>Home Page… “ » “ still stays
and one more question: in my sites, then i am in individual page, the browser address bar looks like this: http://www.tartulinnuklubi.pri.ee/artiklid/132/birding-trip-to-turkey-7-1482008 –
article id between there, but in this page aadress bar i don’t see it. how did you do that?
Instead of having the “Home” text you could replace it with the “txp:site_name” tag. Remember that these changes need to be made to both the “title” and “H1” tags. It’s the “title” tag that displays at the top of your browser window or on browser tabs if you have them.
You can change the way that the URL is constructed by setting the “Permanent link mode” option in the “Preferences” tab. The Bombsite is set to “/section/title”.
i’m not sure where exactly i need to make those changes… :confused: could you do it for me? code i’m using:
<txp:if_article_list>
<txp:if_category><txp:category title=“1” /> category listing. »
<txp:site_name />
<txp:else />
<txp:if_section name=“default”>Home Page<txp:else /><txp:section title=“1” /></txp:if_section> » <txp:site_name /></txp:if_category>
</txp:if_article_list>
<txp:if_individual_article><txp:title /> » <txp:section title=“1” /> » <txp:site_name /></txp:if_individual_article>
I think this is what you need:-
<txp:if_article_list>
<txp:if_category><txp:category title=“1” /> category listing. » <txp:site_name />
<txp:else />
<txp:if_section name=“default”><txp:site_name /><txp:else /><txp:section title=“1” /></txp:if_section> » <txp:site_name /></txp:if_category>
</txp:if_article_list>
<txp:if_individual_article><txp:title /> » <txp:section title=“1” /> » <txp:site_name /></txp:if_individual_article>
Stuart, but now it doubles the sitename in frontpage. take a look
Ah. Of course it does. Try this:-
<txp:if_article_list>
<txp:if_category><txp:category title=“1” /> category listing. » <txp:site_name />
<txp:else />
<txp:if_section name=“default”><txp:site_name /><txp:else /><txp:section title=“1” /> » <txp:site_name /></txp:if_section></txp:if_category>
</txp:if_article_list>
<txp:if_individual_article><txp:title /> » <txp:section title=“1” /> » <txp:site_name /></txp:if_individual_article>
thank you very much Stewart!