WordPress Keyword Description

In most of WordPress themes, there is not meta description and meta keywords handle. This result every page of site has a empty description and keyword in page header, which is not good from search engine’s perspective.

This can be workaround by installing plug All in One SEO. But for those who concern plugin will slow down their sites, here is a simple hack, all needs to do here is just adding a few lines in header.php.

Firstly open header.php, find this line <meta http-equiv=”content-type” content=”text/html; charset=<?php bloginfo(‘charset’); ?>” />

Secondly, add following code after it.

<?php if (is_single()){
$description =  substr(strip_tags($post->post_content),0,220);
$keywords = “”;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
$keywords = $keywords . $tag->name . “, “;
<meta name=”keywords” content=”<?php echo $keywords; ?>” />
<meta name=”description” content=”<?php echo $description; ?>” />

Here is how it works, when a web page is loaded, wordpress will check page type, if it’s a single post, tags strings will be set as keywords and the first 220 letters of post will be set as descriptions. Otherwise, a hard coded keyword and description strings will be set.

Now giving up adding keywords and description in every single post and get rid of All in One SEO.