5

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

5

The 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?

  • 1
    Yes! you were right. strip_tags() does not work because of $content = get_the_content(); $content = apply_filters('the_content', $content); Thank you Mate. – Muhammad Furqan Apr 6 '13 at 22:18
  • Now both solutions worked for me wp_filter_nohtml_kses() and strip_tags() :) – Muhammad Furqan Apr 6 '13 at 22:21
12

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.