DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

I always asked myself why most WordPress theme don’t display any meta description. I created a short recipe to display a meta description, so read on and don’t hesitate to use it on your own theme!

Open your header.php file. Paste the following code anywhere within the <head> and </head> tags:

<?php if (  (is_home()) || (is_front_page())  ) { ?>
<meta name="description" content="Blog description goes here" />
<?php } elseif (is_single()) { ?>
<meta name="description" content="<?php the_excerpt();?>"/>
<?php } ?>

Good job! Your theme now have meta description on the homepage as well as single posts. Also, we should create another conditionnal structure to handle categories.

12 Comments

  1. Thank you so much!
    I have been looking around on how to fix putting a meta tag for my home page for a long time and just did another search and found your site.
    When I first put in the code I figured I’d just have to remove it because of yet another failure, but it worked perfectly! Thank you for posting how to add a meta description to my home page without adding another plugin!

    I will comment on your blog as long as you like! Thanks again!

  2. Do I just put this code in? Or do I have to add words?

  3. Awesome post! This is really helpful. Thanks a lot for sharing 🙂

  4. @Chadd I’m pretty sure that in the code above where it says “Blog description goes here”, you should replace that with your blog description (Eg: write what your blog is about is some sentences).

  5. Cool! I’ve been looking for this forever! Huge help. Thank you.

  6. Thank you for this , just what I was looking for.
    Cheers

  7. Many thanks for providing code to add meta description. Can you provide code for adding meta tags in blogger blogs.

  8. I can’t understand why my blog is not showing although I have placed the above code between the and !

  9. Thanks! Do you have any suggestions to add custom field for meta description in category?

  10. Thank you for this code, but i used it but is not working. There is no in my header.php files, everything says header. Where do you think i can find ..

  11. How do I open the header.php file? I can’t figure it out, and when I look at forums about it, people are saying you can’t. How are y’all doing it?

  12. Thanks for the code, I´ll try to add it. Does anyone know how to add meta description for admin and categories on my WP site? I use a SEO Tools telling me meta description for admin and categories are missing…

Leave a Comment

Your email address will not be published. Required fields are marked *