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

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.

 

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’); ?>

 

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 !

Email this article

Written by on Tuesday, January 12th, 2010

  1. Reader Comments

  2. Amit Agarwal

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

    January 12th, 2010
  3. Soumen Halder

    @Amit Agarwal Thanks Sir. Feels great to find you here.

    January 12th, 2010
  4. Rohit Sane

    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. Soumen Halder

    @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. Simran

    About which snippet Amit sir is talking about ?

    January 13th, 2010
    • Soumen Halder

      @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
  7. Andreas Can

    Dear Amit, I found this article very very interesting & I would like to implement this method to my blog. However – inexperienced as I am – I did not manage to implement it correctly in my index.php.

    If I send you the code line of my index.php file where the excerpt is, would you please be kind enough to consult me where to implement your snippet???

    I would really appreciate your assistance on this!

    December 29th, 2011
    • Amit Banerjee

      @Andreas: Sure. You can get in touch at amit@ampercent.com and send me the code as an email attachment. Dont paste it here, as this page is public.

      December 30th, 2011

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 »

Tip Us »

Have a great tip which you want to share with fellow readers? Send in your ideas to tips@ampercent.com