Textpattern tips, tutorials and code snippets

Adding keywords meta

There are several ways to add page or article specific meta tag keywords, this method uses a custom field to store your keywords.

Name your custom field

In your Admin tab, go to Preferences > Advanced and name one of the unused custom fields as Meta_Keywords.

Add some code to your head tag

<txp:if_custom_field name="Meta_Keywords">
<meta name="keywords" content="<txp:custom_field name="Meta_Keywords" />" />
</txp:if_custom_field>

Add the above code to your <head> tag in your page template. Once you have done this, you can enter specific keywords in your articles. In the Write tab, click on Advanced Options and enter your keywords in the Meta_Keywords field.

3 Comments Comment feed

What advantage does this method offer over just using Textpattern’s built-in Keywords field and tag? Are you using that field for something else?

On a site that uses the smd_tags plugin, I let the tags do double-duty as keywords like so:

<meta name=“keywords” content=”<txp:article><txp:smd_tag_list wraptag=”“ break=”, “ indent=”“><txp:smd_tag_name title=“1” /></txp:smd_tag_list></txp:article>” />

This gives me the benefit of not having to enter the same data twice.

Wouldn’t this be better?

<txp:if_individual_article>
	<meta name="keywords" content="<txp:keywords />" />
	<meta name="description" content="<txp:excerpt />" />
<txp:else />
	<meta name="keywords" content="...">
	<meta name="description" content="...">
</txp:if_individual_article>

dRiZ, an excerpt should be too long for a description, I prefer <txp:link_description /> — e.g.:

<meta name="description" content="<txp:link_description />" />

Add a comment

Use Textile help to style your comments