WordPress.org

Ready to get started?Download WordPress

Forums

echo the excerpt without p tags around (2 posts)

  1. Monika
    Member
    Posted 7 years ago #

    I would like to use the excerpt for
    meta description for single articles

    but if I'm using php echo the excerpt there are the p html tags around the text and html tags between
    head and /head are very crazy ;)

    is their a way to 'delete' this html tags.

    thanks
    Monika

  2. jonathanwagner
    Member
    Posted 7 years ago #

    Try the_excerpt_rss() like this:

    <meta name="description" content="<?php the_excerpt_rss(); ?>" />

    It strips the <p> tags but doesn't seem to strip others. For example I had an <abbr> make it through which kind of messed things up a little.

    Of course, you'll want to put a conditional statement in there to only use the post excerpts for single post pages. Otherwise the first text (usually from the first post) will get posted as the description of your homepage.

    Edited for clarity.

Topic Closed

This topic has been closed to new replies.

About this Topic