WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Removing <p> from the_excerpt (4 posts)

  1. ajaskey
    Member
    Posted 5 years ago #

    I use the_excerpt() to create the description of individual posts.

    <?php if (is_single()) {
    echo (' <meta name="description" content="');
    the_excerpt();
    echo (' ">');
    }
    elseif (is_page())
    ...
    ...

    Each description is enclosed in <p>...</p>. I want to remove this. Is there a function to send the output of the_excerpt through to remove html tags?

    Example of output:

    <meta name="description" content="<p>The Square of 90 is about to complete off the March low with price up over 40%.</p>

    Thanks.
    Andy

  2. Edward Caissie
    Theme Review Admin
    Posted 5 years ago #

    Admittedly my PHP skills are not the greatest but consider the code changes of using the PHP substr and strlen functions:

    <?php if (is_single()) {
    echo (' <meta name="description" content="');
    substr(the_excerpt(),4,(strlen(the_excerpt)-4));
    echo (' ">');
    }
    elseif (is_page())

    Links to the PHP manual for reference, please validate code.
    http://ca.php.net/substr
    http://ca.php.net/manual/en/function.strlen.php

  3. ajaskey
    Member
    Posted 5 years ago #

    cais - Thanks for the suggestion. I found that "the_excerpt_rss()" call does exactly what I want.

  4. randaclay
    Member
    Posted 4 years ago #

    Thank you ajaskey! I've been hunting around for a solution to this for days. Thanks for taking the time to follow up here with your solution.

Topic Closed

This topic has been closed to new replies.

About this Topic