Open Every External Link in New Tab using JavaScript | WordPress

Add given JavaScript code in your Website for open all External link in New Tab. So follow simple steps and make this function in your website without using any third-party plugin or script.

Code

 <script>
function externalLinks() {
for(var c = document.getElementsByTagName("a"), a = 0;a < c.length;a++) {
var b = c[a];
b.getAttribute("href") && b.hostname !== location.hostname && (b.target = "_blank")
}
}
;
externalLinks();
</script>

How To Do

Blogger
Paste this code in your website’s Body section then SAVE your THEME.

WordPress
Open active theme’s footer.php file. Then paste code and SAVE.