Paste the following in functions.php:
/* Make all external links open in a new tab */ function autoblank($text) { $return = str_replace('target="_blank" href=', 'target="_blank" target="_blank" href=', $text); $return = str_replace('target="_blank" target="_blank" href="http://domain.com', 'target="_blank" href="http://domain.com', $return); $return = str_replace('target="_blank" href="#', 'href="#', $return); $return = str_replace('>', '>', $return); return $return; } add_filter('the_content', 'autoblank'); add_filter('comment_text', 'autoblank');
Replace domain.com with the actual domain of your site.
Note: “internal” links should be written in full, not just the extension (“samuelchopard.ch/wiki” and not “/wiki“), if not, “internal” links will be opened in a new tab as well.
Source: https://wjekoslaw.wordpress.com/2013/07/03/making-all-external-links-open-in-a-new-tab-in-wordpress/