WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] strip html from template tag (excerpt) (9 posts)

  1. mattyk
    Member
    Posted 5 years ago #

    Hi

    I'm trying to style the_excerpt().

    I hoped to be able to go <p class="something">the_excerpt()</p> but the excerpt already has the <p> element included.

    Is there a way stripping all HTML from template tags? I tried to use
    <?php strip_tags(the_excerpt());?> but this doesn't seem to work. (sorry my php understanding is limited)

    thanks in advance!!

  2. SteveSmith1983
    Member
    Posted 5 years ago #

    Try this:
    <div class="something"><?php the_excerpt(); ?></div>

    Then in your CSS instead of:

    .something {
        whatever;
    }

    do:

    .something p {
        whatever;
    }
  3. mattyk
    Member
    Posted 5 years ago #

    I think that's what I'm going to have to do, although I really didn't want to have to add an extra Div for such a simple thing.

    Thanks for the reply

  4. SteveSmith1983
    Member
    Posted 5 years ago #

    Is there any way you can target it with what it's in already? What have you got either side of it - can you give me a link to your page?

    Looking back at what you had originally, a less elegant way to achieve what you want is to do this:

    <?php $excerpt = strip_tags(get_the_excerpt());
            echo $excerpt; ?>

    the_excerpt() echoes the excerpt to the screen - it's not a string, so you can't strip the tags out. On the other hand, get_the_excerpt() returns the string that is then filtered and used in the_excerpt().

    Myself I'd go for the extra div or span, but use what works for you.

  5. mattyk
    Member
    Posted 5 years ago #

    Thanks so much for that - perfect.

    I prefer to not add the extra div so this is great

    Thanks again!

  6. SteveSmith1983
    Member
    Posted 5 years ago #

    No problem! :)

  7. Cosmin
    Member
    Posted 5 years ago #

    Cool, thanks a lot Steve, I used it to echo an image alt text.

    Obviously, using <? the_excerpt() ?> in the alt tag was outputing the html tags as well, so i had <p>....</p> as the alt text.

    Now it's perfect, thanks a lot man!

  8. iLm@N
    Member
    Posted 5 years ago #

    wow, this is what I'm looking for.. thanks a lot steve..
    i think the guy here also got the same problem.. i referenced him this thread..

  9. WiBu
    Member
    Posted 5 years ago #

    Appologies for the bump but I've found <?php the_excerpt_rss(); ?> gives you an unfiltered excerpt, the only difference is no <p> tags...

    As far as I can tell anyway.

Topic Closed

This topic has been closed to new replies.

About this Topic