How to be able to add “target” HTML attribute on WordPress profile edit page

One of the first things i liked when starting this new blog based on wordpress, is that, when I was writing my bio, I could use HTML tags on the textarea! (in case you didn´t know it)


But joy turned into “sorrow” when I noticed I couldn´t use the HTML target=”_blank” attribute. It will be simply removed if you try to add it.

target=”_blank” makes possible that when you click on the link, page is opened on a new tab.

I investigated a bit and I found a solution here,

bcworkz tells us it has been made that way for a good reason and it is a poor practice:

According to many UI experts, causing links to open in new windows is not advised. It confuses some users, and users who like links opened in new windows will do so for themselves anyway. It’s poor practice to presume you know what users want to do. WP devs intentionally disallowed the target attribute for this very reason. You may wish to rethink this strategy.

Despite that, I find much more comfortable that the link is opened on a new tab, and the same user kindly gives us the code to do it.

 // Allow target attr in anchor tags

    function bcw_allow_target( $attr, $context ) {

        if ('pre_user_description'== $context ) $attr['a']['target'] = true;

        //"rel" attr allowed by default in this context

        return $attr;


    add_filter('wp_kses_allowed_html', 'bcw_allow_target', 10, 2 );

You must add it on the functions.php file of your wordpress theme. BUT I STRONGLY ENCOURAGE YOU TO CREATE A CHILD THEME FIRST.

Why and how to do that will be a post soon. For the moment take a look here.

What he does is adding a filter. Actions and filters are called in WordPress HOOKS, and are very important on this platform.

As said on this spanish blog, what filter do more or less is to modify the info output before it is recorded on the database or shown on the screen.

For example, one typical filter is called the_content (see available filter list here).

the_content for example can be used to concatenate a text to a given content which will be passed as parameter


/*first you declare what filter must do on a function
function add_text_to_content($content) {
    $content .= " | written by Pablo López";

    return $content;

/*then you use add_filter() in order to be able to use the filter
add_filter( 'the_content', 'add_text_to_content' );

So, with the filter given by bcworkz we are able to append the target HTML attribute to our html code when we are editing our profile page (check it if you want)