Support » Fixing WordPress » Add a specific meta description to homepage only

  • I have WordPress SEO by Yoast installed on my blog. I am having trouble adding meta description to my homepage. Please,don’t assume I haven’t tried google for a solution. I’ve done the Homework.
    So, Joost’s SEO Plugin doesn’t allow you to add a meta description to the homepage. So, what can I do to fix this. I need to add a meta description for my blog.
    I found the code below here but can’t figure out what the <?php the_excerpt();?> should be. I dunno what Joost uses there.

    <?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 } ?>

    And, one more thing I noticed – if I added a description to the head in header.php, using the general code i.e., <meta name=”description” content=”Blog description goes here” />, I get the same description for every article and page when analysed with seocentro’s meta tag analyzer.

    BTW, I use Imag Mag Theme
    So, please help me fix this thing.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Hi Vistatech,

    Yoast SEO plugin does allow you to add a <meta> description tag to your head via the WP-Admin if you have a page set as your front page. However, I’m not too sure if you can do the same with your latests posts displaying as your homepage. ** Someone please correct me if you can actually add it, I don’t have a WordPress install to test this on at the minute **

    Anyway, the reason the_excerpt() is not working as you expect is because you haven’t set up the post object yet. Just call the_post(); before you call the_excerpt(); and it should work.

    Like this:

     // you only need home, because you can edit the front page via wp-admin
    if (  is_home()  ) { ?>
    <meta name="description" content="Blog description goes here" />
    <?php } elseif ( is_single() ) { ?>
    <meta name="description" content="<?php the_excerpt();?>"/>
    <?php } ?>

    However, you will probably be better hooking into wp_head, but the above will work either way.

    That didn’t work for me.
    As for,

    Yoast SEO plugin does allow you to add a <meta> description tag to your head via the WP-Admin if you have a page set as your front page.

    Actually, it doesn’t. I have a page set with permalink to my front page. I tried adding the meta description via the Yoast plugin options which appear below the edit page window, but soon after updating the page all that was typed into the meta description blank just disappears.

    Someone who could help fix this issue??

    Hi Vistatech.

    There are 2 choices for a homepage..

    With Front Page
    This as I have explained in the previous post actually does work, if you look at the source code for: (view-source: you will see the meta description tag. This has been added via the Yoast SEO plugin.

    With Posts as Front Page
    I have also just installed Yoast’s SEO plugin onto a local copy of WordPress to test the meta description when you have posts as your page. This also works as expected.

    Based on what you are saying, its not a problem with Yoast SEO. It’s a problem elsewhere with updating post meta data. Try disabling all of your plugins apart from Yoasts SEO plugin and try again. Ensure your using the latest version of both the plugin and WordPress.

    I can confirm this works, as I have just shown with the above to examples.

    Your right about the code I sent, this doesn’t work (I couldn’t test it, it looked correct). However you don’t need this because the plugin does it.

    Sorry to say, but disabling all plugins and then adding the meta description doesn’t work for me either.

    If you put the above code..

     // you only need home, because you can edit the front page via wp-admin
    if (  is_home()  ) { ?>
    <meta name="description" content="Blog description goes here" />
    <?php } elseif ( is_single() ) { ?>
    <meta name="description" content="<?php the_excerpt();?>"/>
    <?php } ?>

    …in the head, it will not work, as the_excerpt() will ony work within the Loop per this Doc – – last sentence of first paragraph.

    Perhap you could write a function to do this and place it the theme’s functions file.

    I looked at the Page Source (Firefox – right click – view page souce) for each of your six pages and the meta-description only shows on the main page.

    <meta name="description" content="Buttercups Cottage is set in a lovely rural location at the foot of Bodmin moor, close to the village of Bathpool on the river Lynher."/>

    For Accommodations, there is an excerpt from the content:

    <meta property='og:description' content='Originally a 19th century carthouse enjoying rural surroundings, Buttercups has recently been converted into a comfortable 4 berth accommodation boasting a double bedroom with wet room en suite, a twin bedroom plus a family bathroom. The living area combines a kitchen diner space with a cosy lounge area made all the more homely by a [&hellip;]'/>

    An excerpt for Terms & Conditions, as well.

    For the other pages, there is no meta-description or og:description excerpt.

    OK, I did get the description I wanted in the source code… Both in the decsription and og:description i.e.,

    <meta name="description" content="MY DESCRIPTION"/>
    <meta property='og:description' content='MY DESCRIPTION'/>
    and, I also checked these:-

    <meta property='og:url' content=''/>
    <meta property='og:site_name' content='MYBLOG'/>

    Even after having that in the source code, it still doesn’t work for the homepage. I used Meta Tag Analyzer, but it still says I have no description even after having it in the source code of my website. The Meta description displays correctly for every other post when Meta Tag Analyzed. Any ideas?

    @modularbase That code will work, that’s why you call “the_post()” .. this function sets up the post for you based on the page query (which is called before the template is loaded so its fine. it works.

    There is only meta description on the homepage, it has not been set for any other page therefore you will not find it on any other page (this webpage is incomplete). I never asked anyone to look at subpages. The example is on the HOMEPAGE only.

    @vistatech . What’s the URL?

    @crgreay… I have inserted other php code into the head, such as if user is logged in, etc. – but it never occured to me that one could do this, so after some reading, my apologies.

    Further to the problem, it may have a simpler solution.
    Try this: <meta name="description" content="<?php echo the_excerpt(); ?>"/>

    I got this from here

    @modularbase – No worries, it’s good to learn 🙂
    @vistatech – You sorted it yet? 🙂

    Hi All, I was having the exact same problem as Vistatech and found this thread. I know it’s 10 months old but most likely others are ending up here too. Here is what I finally found and it works. Keeps the front page description separate from the posts descriptions . I inserted this code in the header.php file right under the closing meta tag for the title. Hope it works OK for whoever needs it to.

    <?php if ( is_home() ) { ?>
    <meta name=”description” content=”My Description” />
    <?php } ?>

    Credit goes to Jacob Chappell who posted it here at

    Ah, the magic of PHP. That’s the reason I don’t use social plugins for meta tags. 😛 Basically, with if ( is_mark () ) you can personally define any tag you want for any page you want, in one single template (including all and any posts or custom post types).

    Thanks to PAKSTER for the easy php-solution!

    I had been researching this problem for well over an hour, and this seems to be the only suitable solution.

    BTW: if you’re using Yoast SEO stay away from all suggestions to make your header static (to reduce php-executions – like suggested here: ) = you will lose the power of Yoast SEO to insert individual descriptions for each post!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Add a specific meta description to homepage only’ is closed to new replies.