Snippets → WordPress
Add target=”_blank” on all link
just add in function.php
function autoblank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
add_filter('the_content', 'autoblank');
just add in function.php
function autoblank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
add_filter('the_content', 'autoblank');
Personally, I use jQuery to open external links (only) in a new browser window. The problem with the method shown is that any links to the same site will also open in a new window…
This code snippet doesn’t descriminate between links that have had the target=”_blank” already applied by the user and those that have not. It would be better to first do a regex search of the anchor to see what attributes have been applied, then apply the appropriate ones.
As Ross also suggests, there needs to be a way of distinguishing between internal and external links before the target attribute is applied. You could use the rel or class attribute for this, but it still requires some form of manual input.