stripping tags from excerpt in Wordpress is not working
Asked Answered
O

2

11

I am using this snippet

<a href='<?php the_permalink() ?>' title='<?php echo strip_tags(the_excerpt()); ?>

with which I am intending to remove all ellipses, <p> tags and other shortcodes and links, but that does not work at all.

If I hover the anchor, I am still getting to see the <p> wrapped in the excerpt, as well as other tags and the url links. What am I doing wrong and what do I have to do to get it working?

Outgoing answered 31/7, 2013 at 20:58 Comment(2)
You are missing an echo with the_permalink()Recipience
The permalink works without the echo.Outgoing
N
21

What you need is get_the_excerpt():

<a href='<?php the_permalink() ?>' title='<?php echo strip_tags( get_the_excerpt() ); ?>'>

However, it probably won't strip out ellipses (…) since they're HTML entities, not tags.

Nestorius answered 31/7, 2013 at 21:35 Comment(0)
A
5

It's because the_excerpt() outputs the excerpt right away. You want get_the_excerpt() which returns it as a string you can maninpute (http://codex.wordpress.org/Function_Reference/get_the_excerpt).

You can also use wp_filter_nohtml_kses() (http://codex.wordpress.org/Function_Reference/wp_filter_nohtml_kses)

Something like:

$title = wp_filter_nohtml_kses(get_the_excerpt());
Afterburning answered 31/7, 2013 at 21:26 Comment(2)
<a href='<?php the_permalink() ?>' title='<?php echo wp_filter_nothml_kses( get_the_excerpt() ); ?>'>Afterburning
The second solution worked for me, the accepted answer not.Emlin

© 2022 - 2024 — McMap. All rights reserved.