Custom Keywords

When it comes to Search Engine Optimisation (SEO), some people can get very nitpicky. Sitescore.org told me off for using keywords that didn’t appear on my site. This got me thinking about which keywords I should use. I think “Rachael” is definitely a keyword for my site, even though it doesn’t appear on every page.

Wouldn’t it be useful if we could have custom keywords for each page, to help boost our search engine rankings and reduce the amount of people frowning on us for using the wrong keywords? Here’s how to do it using PHP includes.

<?php

include (’header.php’);

?>

That little snippet (or something similar) will probably look familiar to you. It’s how you include your ‘header’ file into each of your pages. We’re going to add to this snippet to display our custom keywords.

First we need to define the variable and give it the values we want for our keywords. For the sake of understandability (is that a word?) we’ll call our variable ‘keywords’.

Our snippet should now look like this:

<?php

$keywords = “keyword1, keyword2, keyword3, keyword4, keyword5″ ;

include (’header.php’);

?>

The keywords variable needs to be defined before we include the header file, otherwise we’ll have errors later on (not good).

Now that we’ve defined our custom keywords, we need to go about displaying them inside our <meta> tags. After all, it’s pointless having all these custom keywords if we can’t tell the search engines about them!

<meta name="keywords" content="

<?php

if (isset($keywords)) {

echo $keywords;

}

else {

echo “default keyword1, default keyword2, default keyword3, etc”;

}

?>

” />

That coding might look a bit daunting at first, so let’s break it down into understandable chunks.

<meta name="keywords" content="

That’s the start of our <meta> tag. It’s how we display the keywords. Next comes some fancy PHP coding (starting with <?php and ending with ?>)

if (isset($keywords)) {

echo $keywords;

}

This means “If the ‘keywords’ variable has been given some values, then display those values”. Not too complicated, I hope.

else {

echo “default keyword1, default keyword2, default keyword3, etc”;

}

This means “If the ‘keywords’ variable hasn’t been given any values, then display these default values”. You might want to use your current ‘un-customised’ keywords for these default values.

" />

Remember that <meta> tag we opened? We need to close it. That’s what " /> is for. However, if you’re using HTML rather than XHTML, you’ll need to put "> instead.

And that’s how it’s done. You can use this technique to define other custom objects in your header file, such as your <title> etc. Good luck!