How to Show Meta Description as Post Excerpts in Blog’s Home page

Written by Amit Banerjee on 12 Jan, 2010 Under Blogging

You may want to show your blog post’s meta descriptions as post excerpts in your blog’s homepage. This may prove to be useful if  you do not want to use the more tag on any of your posts.

Most of the WordPress themes show only a portion of their post in the homepage using the more tag. That means, whatever you include before the “More tag” appears in your blog’s home page and the whole article appears  in the single post pages.

But The Question is “ What if I want to show my  post’s meta description in the home page as post excerpt and the whole article on single post pages ?

(Related : 404 page – useful to readers & meaningful to search engines)

An example to Illustrate

Digital inspiration , a popular technology blog uses a similar feature in their homepage. They show the meta description as post excerpts in the homepage while the single post pages contain the entire article.

meta-description-post-excerpts

The Meta description can be added in your posts using All in One SEO pack a popular seo plugin for WordPress.

Following are the steps involved to show meta descriptions as post excerpts:

1. First back up the index.php file of your current WordPress theme so that if something goes wrong, you can restore things later.

2. Open the index.php file for editing and find the famous WordPress loop. The wordpress loop starts with

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

3. Find the code that shows the post content on the index page. A typical example is:

<?php the_content(‘Read more’); ?>

post-excerpt-code

4. Replace  the above code with the following code :

<?php $home = get_post_meta($post->ID, ‘description’, true); ?>

<?php echo $home; ?>

post-excerpt-code-descriptionThat’s it. Now your blog’s homepage will show the article’s meta description as post excerpts. If you do not add meta descriptions in any  post, no post excerpts will be shown for that article on the homepage. It will only show the title of the article.

Note: Applying the above method shows the meta description as post excerpt in the homepage only. But the category, tag and archive pages will still show the content you are using  just before the more tag. To show the post’s meta description in all your pages, you have to edit the WordPress loop of index.php, page.php and archive.php files. I hope you get the idea.

(Related – Basic On-page SEO Best Practices for new WordPress Blogs)

By the way I am not showing any meta description on the home page as post esxcerpts. I am happy with the in built more tag !

  1. Reader Comments

  2. Instead of using a custom field for excerpts, you can just use the following snippet.

    January 12th, 2010
  3. @Amit Agarwal Thanks Sir. Feels great to find you here.

    January 12th, 2010
  4. Brilliant! Amit sir commenting here is really a great! To be frank, I think that most bloggers just spam in the META description are, so for them this wont be useful, but for people like us, I think this is a really great find. But somehow, I find 160 characters insufficient to describe my post in detail.

    January 13th, 2010
  5. @Rohit Thanks friend. Even we are also elated to find someone like Amit Sir commented here. Ya 160 letter is a bit short, but if it can be done, its better than using another custom excerpt field(as Amit sir mentioned). Or you could leverage the benefits of tag, we do that here at Ampercent.

    January 13th, 2010
  6. About which snippet Amit sir is talking about ?

    January 13th, 2010
    • @Simran The one we explained, since it will help you to avoid creating another custom field for excerpts. He also uses the same in his blog.

      January 13th, 2010

Add Your Comment

All Comments are Moderated.

YOUR COMMENT



About This Site

Ampercent is a technology blog on computer tutorials, software guides, how to tricks and web tools. The blog is updated daily and written by two computer science students from India. Read More »



Subscribe to RSS Feed

Join Our Community

Submit Product For Review

Want a Software or a product to be reviewed ? Tell us about it, we will do the rest.