Skip links

Open External Links in New Window Jquery code

Open ALL links in new window

To open everything in new window, this code can be added in  Settings > General => Header Code:
<base target=”_blank” >

Apply to post external links

To open all external links in the post in a new tab, follow these steps:

1. go to  Settings > General
2. in the Footer Code box, paste this

<script type="text/javascript">// <![CDATA[ jQuery(document).ready(function($){ $('.post') .find('a[href]:not([href^=""]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' ); }); // ]]></script>

3. In the snippet above replace “” with the URL of your own site. Now save and check the site.

Apply to all external links

If you instead want to open all the external links (in content, sidebar, header, footer, etc.) in a new tab, use this code:

<script type="text/javascript">// <![CDATA[ jQuery(document).ready(function($){ $('a[href]:not([href^=""]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' ); }); // ]]></script>

In the snippet above replace “” with the URL of your own site.

Using Plugin

Alternatively, you can use a third party to open external links in a new window – check this plugin.

Leave a comment

This website uses cookies to improve your web experience.
Subscribe To Newsletter
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Give it a try, you can unsubscribe anytime.