Hello, I would like my external links to open in new tab text and image ahrefs. Is there any tag that provides that? I mean tags like this:
This Javascript code might help you out. I’m using it for my own blog like this:
/*
---------------------------------------------
Link Manager
---------------------------------------------
*/
// All links that start with http:// or https:// open in new tabs
// And avoid javascript hrefs to open new blank tab
$(document).ready(function(){
$("body a[href^='http://']").attr("target","_blank");
$("body a[href^='https://']").attr("target","_blank");
// // Open links from source in same page
$(`body a[href^='${window.location.origin}']`).removeAttr("target");
});
Where should I put this code? In [Settings] → Code injection?
You can in the footer injection.
Simply add enclosing tags if you don’t use a custom .js file
<style>
/*
---------------------------------------------
Link Manager
---------------------------------------------
*/
// All links that start with http:// or https:// open in new tabs
// And avoid javascript hrefs to open new blank tab
$(document).ready(function(){
$("body a[href^='http://']").attr("target","_blank");
$("body a[href^='https://']").attr("target","_blank");
// // Open links from source in same page
$(`body a[href^='${window.location.origin}']`).removeAttr("target");
});
</style>
@Alicja_Wachowiak here is a post that covers this issue with a lot of options: