How to open all link in new tab


#1

How can i customize my theme in a way that all the links should open in new tab...

 

 

Regards,

 


#2

you need to add jQuery in the website(if its a wordpress blog, most probably it already is loaded)

then simply add this script in the footer/end of the body to do the job:

  

or you can omit the script tags altogether and put the code in some .js file instead
PS, this is just a quick patch, though you should have some sort of class for the anchor tags(links) so that only those links will be opened in new tab and doesn’t mess up with other link’s functionality


#3

If you need to do this only for external urls, i.e. the urls that does not belong to your domain, then you can use this :

  
jQuery('a').each(function(){  
    if(jQuery(this).attr('href').indexOf(document.domain) == -1)  
        jQuery(this).attr('target','_blank');  
});  

#4