質問

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

役に立ちましたか?

解決

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?

他のヒント

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

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.

seen here

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top