Support » Plugins » Is there a tag to include excerpt in meta description?

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

    Thanks

    Paul

Viewing 11 replies - 1 through 11 (of 11 total)
  • 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.

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

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

    Thread Starter Pauls

    (@pauls)

    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.

    Thanks

    dylan

    (@dylan)

    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?

    Kafkaesqui

    (@kafkaesqui)

    http://codex.wordpress.org/Template_Tags/the_excerpt

    “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()) :
    get_posts('numberposts=1');
    foreach ($posts as $post) :
    $excerpt = $post->post_excerpt;
    endforeach;
    ?>
    <meta name="description" content="<?php echo htmlentities($excerpt); ?>" />
    <?php endif; ?>

    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.

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

    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.

    I guess the plugin isn’t working?

    Brian, it’s a matter of well-formed HTML, and:
    http://wordpress.org/support/topic/31266

    Kafkaesqui, that little workaround was wonderful, thank you.

    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?

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Is there a tag to include excerpt in meta description?’ is closed to new replies.