Is there a tag to include excerpt in meta description? (12 posts)

  1. Pauls
    Posted 11 years ago #

    Hi all,

    I'm setting up a new WP blog and was wondering if there's an include tag or hack to insert the post excerpt in the individual pages meta description area. Can it even be done?



  2. NuclearMoose
    Posted 11 years ago #

    I'm curious to know why you would like to do that. Not being a smart@ss or anything...I genuinely don't know why someone would want to do that.

  3. moisie
    Posted 11 years ago #

    I think my metatags plugin will do what you want: moisie_templates_metatags

    Unless you mean the output of the_meta() within each page.

  4. Pauls
    Posted 11 years ago #

    Hi moisie. I think that'll work.

    And Moose - It's the unique meta description tag I'm after, so that when my individual posts show up in search engines, the descriptions in the listings not identical to all my other posts.

    I had a hunch this could be done because the title tag can be different for each WP post, so inserting something in a meta description tag couldn't be too difficult.

    I'll give it a whirl and see what happens.


  5. dylan
    Posted 11 years ago #

    You would think this would work:

    <?php if ( is_single() ) { ?>
    <meta name="description" content="<?php the_excerpt(); ?>" />
    <?php } ?>

    but it doesn't quite work, and that's a shame.

    I found a suggestion to use

    <meta name="description" content="<?php echo htmlentities(get_the_excerpt()); ?>" />

    but that also doesn't seem to work for my wordpress 1.5 blog.

    am I missing something?

  6. Kafkaesqui

    Posted 11 years ago #


    "This tag must be within The Loop."

    You need a bit of script that extracts the excerpt from the database outside of The Loop. There's a few ways I can think of doing that, but here's an example that makes use of get_posts():

    <?php if(is_single()) :
    foreach ($posts as $post) :
    $excerpt = $post->post_excerpt;
    <meta name="description" content="<?php echo htmlentities($excerpt); ?>" />
    <?php endif; ?>

  7. DianeV
    Posted 11 years ago #

    NuclearMoose, if I'm understanding your question, the answer is simply that some search engines display the meta description in their search results.

    I'm a bit surprised that this was left out of WordPress; lack of a meta description makes WordPress' output incomplete. If there is no easy way to fix this (such as 1.2's use of the_excerpt), that's why people are writing plugins -- they're fixing something that should have been included in the first place.

    Kafkaesqui, for some reason I'm not having any luck with that, either.

  8. brianbonner
    Posted 11 years ago #

    I don't know how this can be a big problem since allot of my traffic comes from search engines.

  9. richards1052
    Posted 11 years ago #

    Moisie: I tried installing your plugin w/o success. I tried leaving a comment in the plugin post but received a 404 error fr. your server.

    I've just installed the file in my plugins folder. When I visit my Plugins activation screen I see the entire file displaying where there should be a single line describing the plugin. I clicked on the activation link & visited my Write screen to see where or if the metatag feature displayed. I can't find anything.

    This plugin is dead meat unless someone can help me figure out what I did wrong.

  10. DianeV
    Posted 11 years ago #

    I guess the plugin isn't working?

    Brian, it's a matter of well-formed HTML, and:

  11. joelwalsh
    Posted 10 years ago #

    Kafkaesqui, that little workaround was wonderful, thank you.

  12. kektex
    Posted 9 years ago #

    Sorry for bumping this old thread but I`ve been using Kafkaesqui´s solution above to this problem but since my blog is pretty old there are now many pages with an empty meta description tag.
    How can Kafkaesqui´s code be modified so that if the excerpt field is empty, the whole meta description tag is left out of the page?


Topic Closed

This topic has been closed to new replies.

About this Topic