Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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 the class attribute only):

add_filter('pre_user_description','wpse_whitelist_tags_in_bio');
function wpse_whitelist_tags_in_bio($description){
    $bio_allowed_tags = array(
                         'strong'=>array(),
                         'em'=>array(),
                         'h1' => array(
                            'class' => array (),
                        )

    $description = wp_kses($description,$bio_allowed_tags);
    return $description;
}

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 use wp_strip_all_tags()

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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