WordPress / PHP / Magic Fields Strip unnecessary HTML Tags while leaving the ones you want

HI Its really annoying when WordPress sometimes adds tags in multiline text inputs when you really dont need them. So to get rid of those tags you can use the following php function,


Here the string part refers to the string that your getting through WordPress or maybe as a Magic fields input field. and you can use the allow part to allow any tags that you might actually want to leave in the out put.


strip_tags($postextract, '<a><ul>');

This will actually strip all HTML tags leaving anchor tags and UL tags in the output. Pretty useful hack. 🙂

Reference :


Let me know what you think .. :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.