How to add a target = "_blank" to all links under WordPress


Wordpress Under WordPress, it is easy to add a target = "_blank" as soon as you add a link in an article or a page, just check the box "open the link in a new window/a new tab" when inserting the link. But the problem arises when you want to do this for the entire site that contains hundreds or even thousands of links! Do this one by one… No thanks! So to add the target = "_blank" to all the links of your site under WordPress, you have to edit the file functions. php (or custom-functions. php if supported) of the theme used, and add this:

function autoblank ($text) {$return = str_replace (' < a ', ' < a target = "_blank" ', $text); return $return;} add_filter (' the_content ', ' autoblank ');

Save your file, and hop, now all your links will open in a new tab!  

Leave a comment

Your email address will not be published.