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^="https://wpdeveloperking.com"]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' ); }); // ]]></script>
3. In the snippet above replace “https://wpdeveloperking.com” 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^="https://wpdeveloperking.com"]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' ); }); // ]]></script>
In the snippet above replace “https://wpdeveloperking.com” 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.