« The Smart Easy Road From PowerPoint To YouTube  |  Customizing Google Docs Form For Email Validation Using Free jQuery Script »

Embedding Title & Description Meta Tags In WordPress Posts & Pages

Comments §

WordPress is popular because primarily it is easy to use. Free WordPress templates are available in abundance, so are the widest varieties of plug-ins which too are free to use.

Given all that, it is a bit surprising that WordPress doesn’t give the options to have separate title and description meta tags for the posts and pages you create.

Since these 2 tags are important considerations for search engine optimization, you have to therefore look for workarounds to be able to easily embed the title and description meta tags in both WordPress posts and pages.

Fortunately, this is not difficult to do. The video below shows you how to do it, followed by step-by-step details.

 

 

Embedding Title Meta Tag In WordPress Posts & Pages

To do this we will install the popular WordPress plugin, All in One SEO Pack.

  1. Go to this page, and download the plugin zip file. Unzip, and then FTP-upload the entire plugin folder (NOT just the individual php files) to your web-server directory, /wp-content/plugins/.

    You can also use WordPress’ in-built plug-in search facility in the Install Plugins page to locate this plugin, and then automatically install it in your blog. This is easy to do, and you can avoid the above lengthy steps.

  2. Open your WordPress blog’s admin panel, the Dashboard, in your browser, and locate the plug-in in the plug-ins menu.
  3. Configure the plug-in options as necessary, and activate/enable the plug-in.

If you now want to add a new post or a page, WordPress will present you the All in One SEO Pack option of including the title and the description for that post or page. See the image below.

Adding title and description meta tags

All in One SEO Pack's options to add title & description meta tags

Since what you write here will be the page title of the post/page, keep it short but don’t forget to include the relevant key-phrase in it. Remember, you also have the title of the post/page above, which will now appear as the heading of the article you write.

All in One SEO Pack provides the option of description meta tag as well, but in my experience this doesn’t work. Why? I don’t know.

So you need to find out some other means to do it.

Embedding Description Meta Tag In WordPress Posts

Let us look at some of the options here, and their pros and cons:

  1. The easiest way out is putting the following piece of code in the header area (‘header.php’ file).

    <meta name=”description” content=”<?php bloginfo(‘description’); ?>” />

    The problem is that this code mentions the same description for all the posts and pages. And that description is usually nothing but the Tagline of your blog in the Admin > Settings > General page. Perhaps you don’t want this as meta description for your blog posts.

  2. A viable option is to use the excerpt of the post you write in the description meta tag. The following image illustrates it. In this case, the code in the header area for the description meta tag will change to:

    <meta name=”description” content=”<?php the_excerpt(); ?>” />

    Excerpts for meta description

    Using excerpt to work as meta description of WordPress posts and pages

    This works pretty well but there still remains a problem. What happens in many cases is that when you look at the HTML source code of the post, you’ll see a pair of <p> tag appearing in the description meta tag as shown under:

    <meta name=”description” content=”<p>blah, blah, blah…</p>” />

  3. To overcome this problem yet another change is needed in the code. The final piece of code is given below. Embed it in the header area, and from now on whatever you mention as the excerpt for a post will appear as the description for that post page.

    <meta name=”description” content=”<?php echo get_the_excerpt(); ?>” />

Embedding Description Meta Tag In WordPress Page

Okay, the posts in WordPress will have the description meta tag as explained above. What about the pages? Usually, WordPress doesn’t allow the excerpt box for the pages even though both the posts and the pages will ultimately reside in the same database table.

However, not all hopes are lost. If you are using the latest release of WordPress, include the following piece of code in the file, functions.php. For more on this, go here.

add_action( 'admin_menu', 'mf_add_page_excerpt_box' );
function mf_add_page_excerpt_box() {
add_meta_box( 'mf_page_excerpt', __( 'Excerpt' ), 'mf_page_excerpt_box', 'page', 'normal', 'high' );
}
function mf_page_excerpt_box() {
global $post;
$message = __( 'Excerpts are optional hand-crafted summaries of your content. You can use them in your template' );
print < < <div class="inside">
<textarea rows="1" cols="40" name="excerpt" tabindex="3" id="excerpt">{$post->post_excerpt}</textarea>
<p>{$message}</p>
</div>
EOF;
}

Conclusion

WordPress says that code is poetry. Indeed it is so for, as you can see above, it is possible to do quite a lot when you know how to do coding, or at the least how to use codes that are already freely available. I belong to the second category, and so far I’ve immensely benefited by using WordPress.

One of that would certainly be the ability to embed the title and description meta tags in my posts and pages.


This article of May 3rd, 2010 is authored by Partha Bhattacharya, who runs this website. Catering to the clients' video needs aside, Partha also writes guest articles for other web publications.
Enroll with our video production course

§ 3 Replies

  • Recent Articles

Get Adobe Flash playerPlugin by wpburn.com wordpress themes