i want to remove all html tags from content like <p>, <br>, <img>, <a>
i tried strip_tags()
also tried
$content = get_the_content();
$content = apply_filters('the_content', $content);
but not working for me. any reliable solution ??
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityThe WordPress function, at least the one I tend to use, would be wp_filter_nohtml_kses
. That should remove all of the HTML, but you need to be careful not to put some HTML back by running the_content
filters on your HTML-less string.
I am not sure why strip_tags
didn't work, but I suspect that you doing something else in other code posted or not posted and that that something else is undoing your tag stripping, or putting some tags back. Mainly I think that because you tried ...
$content = get_the_content();
$content = apply_filters('the_content', $content);
... and apparently expected tags to be stripped?
strip_tags()
does not work because of $content = get_the_content(); $content = apply_filters('the_content', $content);
Thank you Mate.
Apr 6, 2013 at 22:18
wp_filter_nohtml_kses()
and strip_tags()
:)
Apr 6, 2013 at 22:21
To build upon @s_ha_dum's answer I think you want.
$content = get_the_content();
echo wp_filter_nohtml_kses( $content ); //or strip_tags
wp_filter_nohtml_kses( apply_filters( 'the_content', $content ) )
?
This removes both <htmltags>
and <!-- comments -->
:
echo wp_strip_all_tags( get_the_content() );
wp_filter_nohtml_kses()
didn't get me rid of the comments.