Recent Posts
- 10 Things To Do When Launching A Site
- Using PHP to connect to SFTP
- Asynchronous Virtual Pageviews with Google Analytics
- 5 Advanced Text Editing Keyboard Shortcuts
- Get the headers of a HTTP request with PHP
- How-to: Create PDF preview images in PHP – Part 2
- How-to: Create PDF preview images in PHP
- Quick Code: Get the domain name in JS
- Things to think about when designing a logo
- Javascript Array Functions
Topics
Using WordPress Tags as Keywords
Posted on 3rd March 2009 by Jacob Wyke
Tags in WordPress allow you to organise your content with quick and easy Folksonomy. This can then be used to view or show other related data or fancy, but not very usable, tag clouds. Today we will see if we can’t make more use out of this information by adding it to our meta keywords for better SEO.
This is a simple piece of code that you can use in your WordPress templates that uses the posts tags as keywords in the <head> section of your code.
//get the page keywords
$strPageKeywords = "";
if(is_single()){
while (have_posts()){
the_post();
$arrPostTags = get_the_tags();
if($arrPostTags){
foreach($arrPostTags as $arrTag) {
$strPageKeywords .= $arrTag->name . ', ';
}
}else{
//default keywords if no tags are used
$strPageKeywords .= "";
}
}
}else{
//default tags for the rest of the site
$strPageKeywords .= "";
}
You then have a PHP variable with the keywords in that you can use.
<head>
<meta name="keywords" content="<?=$strPageKeywords;?>"/>
...
</head>
Then just start to tag your blog posts with descriptive tags and these will be used as the pages keywords and help you get better indexed in search engines.
Further Reading
Have Your Say
Comments
-
Toby on 18th July 2010 wrote:
Works excellently, thanks for writing this.
-
Deepak on 21st February 2011 wrote:
Works great. Thanks!
Buzz Around This Post
-
amosisreal » Alter Wordpress to automatically use post tags as meta keywords
Added on 3rd August 2011
Jonathan on 5th February 2010 wrote:
Tried this out on my site, i first had to embed it in tags but when i look at the page source, instead of tags i see the code ‘ content=”"‘
Any suggestions?