I need a function that I can use that will remove <div> and </div> tags from a string. I have tried esc_attr(), and even wp_strip_all_tags() --- none of them work. They all leave the <div> and </div> tags in the string - which causes certain social-media buttons to turn out in ways that really do not look good.

Any suggestions what to do?

  • 1
    Can you show us how are you using wp_strip_all_tags() and it is not stripping <div>? – cybmeta Jun 12 '15 at 7:59

Use a PHP function to do this: https://php.net/strip_tags


echo strip_tags("<div>my text</div>");
| improve this answer | |

If it's only <div></div> I would do a preg_replace, like this:

$string = preg_replace ( '|</?[^>]*>|i', '', $string );

This removes only the tags, not the text between the Tags. I understood this is what you wanted.

| improve this answer | |

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.