WordPress.org

Ready to get started?Download WordPress

Forums

Add a specific meta description to homepage only (15 posts)

  1. vistatech
    Member
    Posted 1 year ago #

    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.

  2. crgeary
    Member
    Posted 1 year ago #

    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:

    <?php
    the_post();
     // 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.

  3. vistatech
    Member
    Posted 1 year ago #

    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.

  4. vistatech
    Member
    Posted 1 year ago #

    Someone who could help fix this issue??

  5. crgeary
    Member
    Posted 1 year ago #

    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: http://buttercupscottage.co.uk/ (view-source:http://buttercupscottage.co.uk/) 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.

  6. vistatech
    Member
    Posted 1 year ago #

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

  7. ModularBase
    Member
    Posted 1 year ago #

    If you put the above code..

    <?php
    the_post();
     // 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 - http://codex.wordpress.org/Function_Reference/the_excerpt - last sentence of first paragraph.

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

  8. ModularBase
    Member
    Posted 1 year ago #

    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.

  9. vistatech
    Member
    Posted 1 year ago #

    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"/>
    and
    <meta property='og:description' content='MY DESCRIPTION'/>
    and, I also checked these:-

    <meta property='og:url' content='http://MYBLOG.com/'/>
    <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?

  10. crgeary
    Member
    Posted 1 year ago #

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

  11. ModularBase
    Member
    Posted 1 year ago #

    @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 http://stackoverflow.com/questions/10382178/create-mini-loop-in-the-head-to-use-advanced-excerpt-loop-to-use-current-post

  12. crgeary
    Member
    Posted 1 year ago #

    @ModularBase - No worries, it's good to learn :)
    @vistatech - You sorted it yet? :)

  13. Packster
    Member
    Posted 2 months ago #

    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 http://wordpress.org/support/topic/how-do-i-add-a-page-description-to-the-home-page

  14. GeorgeDK
    Member
    Posted 2 months ago #

    Ah, the magic of PHP. That's the reason I don't use social plugins for meta tags. :P 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).

  15. webbeetle
    Member
    Posted 1 month ago #

    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: http://lorelle.wordpress.com/2007/09/22/the-3-easiest-ways-to-speed-up-wordpress/ ) = you will lose the power of Yoast SEO to insert individual descriptions for each post!

Topic Closed

This topic has been closed to new replies.

About this Topic