Optimize your WordPress theme for Search Engines – Part 3

WordPressThis 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 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; ?>

Line 5 thru 7 are the ones that deal with the keywords.

<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 . ','; } } ?>" />

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.

About Jeremy Clark

Small town IT worker with interests in all things technological and technical. Biggest interests are in web development especially the WordPress publishing platform and the community supporting it. Currently developing and maintain the free WordPress theme Techozoic. I'm also always available for hire.
This entry was posted in wordpress and tagged , , . Bookmark the permalink.

Leave a reply

Comments will be sent to the moderation queue.