This is the 3rd and final post about SEO for your WordPress theme. Meta keywords used to be what all search results where based on but over time webmaster began abusing this to gain rank, today some say that they are ignored all together when calculating search results but if they’re not then having your posts tags and categories added couldn’t hurt. This is the code goes between the <head> </head> tags. This also includes the meta description code from yesterday’s post.
[php]<?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<meta name="description" content="<?php $excerpt = strip_tags(get_the_excerpt());
echo $excerpt; if ( $cpage < 1 ) {}
else { echo (‘ – comment page ‘); echo ($cpage);} ?>" />
<meta name="keywords" content="
<?php foreach((get_the_category()) as $category) { echo $category->cat_name . ‘,’; }
$posttags = get_the_tags();if ($posttags) {foreach($posttags as $tag) {echo $tag->name . ‘,’; } } ?>" />
<?php endwhile; endif; elseif(is_home()) : ?>
<meta name="description" content="<?php bloginfo(‘description’); ?>" />
<?php endif; ?>[/php]
Line 5 thru 7 are the ones that deal with the keywords.
[php firstline=”5″]
<meta name="keywords" content="
<?php foreach((get_the_category()) as $category) { echo $category->cat_name . ‘,’; }
$posttags = get_the_tags();if ($posttags) {foreach($posttags as $tag) {echo $tag->name . ‘,’; } } ?>" />
[/php]
This code depends on the loop code on line 1 to be able to pull the posts category and tags. This code basically pulls each category out and prints it out follow by a comma and then does the same with the tags. The comma is important because that is what separates the keywords. Even if this has marginal benefit it’s not that hard to implement and the cost as far as page load time should be minimal.
You see the whole series here. Be sure and rate each post, thanks.
