WordPress: Dynamic Meta Description and Keywords howto

This is a quick guide to add dynamic meta description and keyword to each different url of our Wordpress blog, very useful to SEO users.

Open your header.php file from your theme directory and put this code into:

Meta Content Description

<meta name="description" content="
<?php if (have_posts() && is_single() OR is_page()):while(have_posts()):the_post();
$out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", get_the_excerpt());
echo apply_filters('the_excerpt_rss', $out_excerpt);
endwhile;
elseif(is_category() OR is_tag()):
if(is_category()):
echo "Posts related to Category:
".ucfirst(single_cat_title("", FALSE));
elseif(is_tag()):
echo "Posts related to Tag:
".ucfirst(single_tag_title("", FALSE));
endif;
else: ?>
ADD HERE YOUR DEFAULT DESCRIPTION
<?php endif; ?>" />

Meta Content Keywords

<meta name="keywords" content="
<?php
$tags = get_tags(array('orderby' => 'count', 'order' => 'DESC'));
$xt = 1;
foreach ($tags as $tag) {
if ($xt <= 20) {
echo $tag->name.", ";
}
$xt++;
}
?>ADD, HERE, YOUR, STATIC, KEYWORDS" />
Tags: , , , , , , ,

Post simili:

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

6 Responses to “WordPress: Dynamic Meta Description and Keywords howto”
  1. newborn gift
    22:38 on July 27th, 2008

    very cool thanx buddy, is there a plugin that does this so we don’t have to manually edit the header.php file? Either way its super useful.

  2. 3d
    17:39 on July 30th, 2008

    Thank for share this tips!… now i can try… :)

  3. Miami Mike
    14:38 on August 6th, 2008

    Keywords aren’t useful for SEO any more. That’s what Google Guys say.

  4. Aaron Stroud
    07:11 on August 12th, 2008

    Thank you, thank you, thank you! This was code was exactly what I was looking forward to! Thank you for sharing!

  5. eylultoprak
    12:20 on August 28th, 2008

    Thank you, thank you, thank you.

  6. Tila Tequila Naked
    21:11 on August 29th, 2008

    Hey =) Just check this out: Tila Tequila is naked uhhhh…. hot bitch: http://tilatequilanaked.0catch.com/

Leave a comment

(required)

(required)



Comments links could be nofollow free.

Categories