Links in new tab


I am using Fashionistas theme on a blog and I am looking for a short CSS code that will open all of my links that are clicked in a new tab by default (sidebar and main blog).

Is this something that can be easily adjusted? Thank you!

Hi there,

You can’t do that by using the CSS code, but you need a javascript code instead.
Firstly, please install this plugin and activate it, then put this javascript in there:

jQuery('a').attr('target', '_blank')


Worked like a charm! Thank you for helping me!

1 Like

Hi Awan,

Is it possible to tweak this query to exclude my menu links from opening in a new tab? I just realized my menu items in the top header that include “About,”“Blog,” and “Contact” will also open in new tabs

Of course, please add this below the code above:

setTimeout(function(){ jQuery('#main-navigation a').attr('target', '_self') }, 700)

Thanks again - is it possible to also tweak that to exclude the sidebar? I would like all sidebar links to open in a new window.

Both codes above should make the sidebar link to open the page to a new window. If it’s not working, can you please share your site URL here?

Sure -

The main menu links work perfect however the sidebar links are not opening in a new window

There is an error when you put the code above to your site. You put it like this:

jQuery('a').attr('target', '_blank')
setTimeout(function(){ jQuery('#main-navigation a').attr('target', '_self')

And what I mean is, you need to put the code like this:

jQuery('a').attr('target', '_blank')
setTimeout(function(){ jQuery('#main-navigation a').attr('target', '_self') }, 700)

Thank you for catching that error. I went ahead and tweaked the code again and it opens the sidebar menu in a new tab just as I wanted but now the top menu is opening in new tabs as well.

Hmm… how if you increase the number from 700 to 1500?

Or, try this code instead:

    jQuery('a').attr('target', '_blank')
    setTimeout(function(){ jQuery('#top-navigation a').attr('target', '_self') }, 700)

That second code worked perfect! Thank you for troubleshooting this. Everything opens in its intended window now.

1 Like