• Resolved mattyk

    (@mattyk)


    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!!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try this:
    <div class="something"><?php the_excerpt(); ?></div>

    Then in your CSS instead of:

    .something {
        whatever;
    }

    do:

    .something p {
        whatever;
    }

    Thread Starter mattyk

    (@mattyk)

    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

    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.

    Thread Starter mattyk

    (@mattyk)

    Thanks so much for that – perfect.

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

    Thanks again!

    No problem! 🙂

    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!

    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..

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘strip html from template tag (excerpt)’ is closed to new replies.