WordPress categories, optimization tips and custom pages

web design cyprus

It’s not a SEO secret, inner links to / from strong category pages will help your site to rank higher in Google. Sad enough that WordPress doesn’t provide a lot of functionality for these important sections on your blog site. This is the information you can read below the field “description” if you edit a category:

The description is not prominent by default, however some themes may show it.

There is no field for a second title and the description field doesn’t allow most of the HTML elements. I’m using the All in One SEO plugin because it gives me the freedom to write a custom page title or meta description (for posts or pages only). Most SEO plugins doesn’t care a lot about category pages…

First preparations

In my experience it’s the best to not index any archive page created by WordPress because they show content duplicates. The category URL could need an update first: By default you get this kind of category URL:


We need to remove the “archives” part from the URL, goto Settings->Permalinks and add some unique name for the field “Category base”.

If you use the “All in One SEO” like I do, disable the following settings:
Canonical URLs, Use noindex for Categories

Head to the plugin category, open the file (aioseop.class.php) and disable (//) row 283 to disable the creation of a meta description for all category pages:

//$description = $this->internationalize(category_description());

This function is buggy because the auto generate option will use the complete category text for a meta description.

We will create for the category pages our own META information and the canonical URLs for posts and pages are created by WordPress since version 2.9. Next you need to create some unique text for all the categories, 100 words is a great text length.

Optimizations for the “generated” category pages

We need to create some code to get the right META data in our header section. In the theme directory is a file called “functions.php”, open the file in a text editor and add this code:

function create_short_version($text, $len = 150) {
	$parts = explode(' ', $text);
	$ic = count($parts);
	$txt = '';
	for ($i = 0; $i < $ic; $i++) {
		$txt .= $parts[$i].' ';
		if (strlen($txt) >= $len) break;
	$txt = trim($txt).'...';
	return $txt;
function fix_meta_canonical() {
	global $paged;
	if (is_category()) {
		$catid = get_query_var('cat');
		$catdescr = strip_tags(trim(category_description($catid)));
		if (strlen($catdescr) > 160) {
			$meta = create_short_version($catdescr);
		} else {
			$meta = $catdescr;
		echo '
<link rel="canonical" href="'.get_category_link($catid).'" />
<meta name="description" content="'.$meta.'" />';
		if ($paged > 1) echo '
<meta name="robots" content="noindex,follow" />';
	} else {
		echo '';
add_action('wp_head', 'fix_meta_canonical');

The first function “create_short_version()” is a helper which creates a short version from a text without changing the last word into something unreadable. Inside the function “fix_meta_canonical()” we create additional META information if the current page is a category. We don’t allow search engines to index other category pages than the first page.

Now we need to change our default theme file. Open the file “archive.php” (or category.php) and add the following code right below the header element and before the loop:

	if (is_category() && $paged < 2) {
		echo '

Using this code the category page will show the description as well, but only on the first page!

Optimize your most important categories

I use for most of my blog posts more than one category, for example this article is listed in the categories “PHP Scripts” and “Search engine optimization”. If you analyze your blog you will see that some category is more important or is used more often. While the steps above are okay for most the categories, it might be better to create a custom or static page for some of your categories. We did this for the category PHP Scripts.

With WordPress it’s possible to create a static page for just a single category. How does it work? Create a copy of the “archive.php” file and call it category-XX.php where XX is the category ID from the category you like to create a static page for. You can find the ID in the browser’s address bar if you edit a category. Add your custom code and the category description to this newly created file and save your work. I use the static content only for the first page and show the regular code for all underlying pages:

if (is_category() && $paged < 2) { 
    // show here your custom code/content
} else {
    // show here the code from your archive.php file

Don’t remove any code from outside the DIV container with the ID “content”. This modifications are only for the “information part” and about the design or the layout.

Header and title improvements

For SEO reasons it’s much better to have different titles in the page title and your header element. With the following code it’s possible to tweak the page title as well:

// create here your custom titles
$my_pagetitels = array(
	4 => 'PHP scripts and tutorials'
function change_cptitle() {
	global $my_pagetitels;
	$catid = get_query_var('cat');
	if (array_key_exists($catid, $my_pagetitels)) {
		$title = $my_pagetitels[$catid]; // use a custom title
    } else {
    	$title = get_the_category_by_ID($catid); // use the category name as title
    return $title;
add_filter("single_cat_title", "change_cptitle");

Sure this solution is very quick and dirty, but it works :) Add your custom titles within the array which is called “$my_pagetitels”. Use the category ID as array index number and enter the “page title” as value. The function will check the array for an existing value and will use the category name as alternative. With a static value for your header element you use three different values instead of only one (the category name).

Don’t forget to add the category pages to you’re Google Sitemap. Remove the categories from your “robots.txt” file if you blocked them before.


Leave a Reply