HTML Meta Tags

When I created this website, I decided that I would use custom and unique description and keywords meta for each blog post. The idea here was to make each page a bit more individual in the eyes of search engines. I realize that search engines no longer place much (if any) weight on these factors, but it doesn’t hurt to be thorough.

The original implementation of the html head was like so:

<?php
if(is_single() || is_page()) {
    $description_meta = get_post_meta($post->ID, "description", true);
    $keywords_meta    = get_post_meta($post->ID, "keywords", true);
}
else if( is_category() ) $description_meta = category_description();

if("" == $description_meta) $description_meta = get_bloginfo('desciption');
if("" == $keywords_meta)    $keywords_meta    = "curtis,tasker,curtis tasker";
?>

<meta name="description" content="<?php echo($description_meta); ?>"/>
<meta name="keywords" content="<?php echo($keywords_meta); ?>"/>

Every post or page in WordPress has a nice little GUI for entering Custom Fields of data. By using these, I would be able to customize each blog post’s metadata, while maintaining the default for the rest of the pages.

While this performed admirably, I recently did a little improvement. While working on something totally unrelated, I realized that the post tags and keywords meta for each blog post were almost exactly the same. Apparently the overlap never occurred to me when I first built the site.

A solution was actually pretty simple:

$keywords_meta = implode( ",", wp_get_post_tags( $post->ID,
                                                 array('fields'=>'names') ));

Now it pulls the list of tags for the blog post, then converts it into a comma-delimited string, and uses that for the keywords meta. All in all, a much cleaner solution that speeds up the process of publishing a blog post. Every little bit helps.

Leave a Reply

Comments from new authors must be approved before they will appear.
After your first comment is approved, you are free to comment at will.