How to Open Links in a New Tab

It is very easy to make your link open in a new tab without using any plugin, but before making these changes, please make sure you are using child theme

If you don't want to create a child theme then you can use the following plugin: https://wordpress.org/plugins/custom-css-js/ it's important to note that the plugin might already add the:

 <script type="text/javascript"></script>

Tags for you so you might not need to add it.

This doc cover three different ways of opening a link in a new tab:

1) If you want to open all link available on your site in new tab then, open your header.php file and add this code just above </head>

<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function($){
    $('a').each(function(){
        if( $(this).attr('href') && 0 != $(this).attr('href').indexOf('#') ) {
            $(this).attr('target', '_blank');
        }
    });
});
// ]]></script>

2) If you want to open external link available on your site in new tab then, open your header.php file and add this code just above </head>

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

Make sure you replace " ENTER YOUR SITE URL HERE " with your site URL.

3) If you want to open any particular link on your site in new tab then, open your header.php file and add this code just above </head>

<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function($){
    $('#footer .social li a').each(function(){
        if( $(this).attr('href') && 0 != $(this).attr('href').indexOf('#') ) {
            $(this).attr('target', '_blank');
        }
    });
});
// ]]></script>

Make sure you replace " #footer .social li a " with the particular class of which link you want to open in a new tab.

This video might come in handy if you are trying to open just a specific link in a new tab: