I want to automatically remove any kind of links from author’s Biographical Info instead of doing it manually everytime. Whenever a user adds any link to the Biographical Info box, it should be automatically striped off when it’s viewed on the blog.
Leave a Reply
You must be logged in to post a comment.
You can use
pre_user_description
hook, which filters the user’s description prior to saving/updating the user, to remove any unwanted tags.To do that, you can use the
wp_kses
function, which strips out all but whitelisted tags.The allowed tags should be given as an associative array, where the keys are the names of the tags, and the values are an array of allowed attributes for this tag.
For example to allow only
<strong>
and<em>
tags (without any attributes) and the<h1>
tag (with possibly theclass
attribute only):wp_kses
is an expensive function, so it should only be run when data is saved, not displayed. To strip out all HTML tags, you can usewp_strip_all_tags()