{"id":8286,"date":"2017-01-17T06:06:51","date_gmt":"2017-01-17T06:06:51","guid":{"rendered":"https:\/\/themehunk.com\/?post_type=docs&#038;p=8286"},"modified":"2020-11-21T11:46:14","modified_gmt":"2020-11-21T06:16:14","slug":"open-links-new-tab","status":"publish","type":"docs","link":"https:\/\/themehunk.com\/fr\/docs\/open-links-new-tab\/","title":{"rendered":"How to Open Links in a New Tab"},"content":{"rendered":"<p>Lots of plugins are available to open links in a new tab but every time using a plugin is not good. So here I am giving you a simple and easy solution to open link in a new tab using coding. Just follow the instructions given below:-<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>As you have external links in your site and you want to open them in a new tab by clicking on them. For that you need to use a simple code in your header.php file just above the &lt; \/head&gt; mentioned below:-<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>[js]<script type=\"text\/javascript\">\/\/<![CDATA[ jQuery(document).ready(function($){ $('a[href]:not([href^=\"SITE URL\"]):not([href^=\"#\"]):not([href^=\"\/\"])').attr( 'target', '_blank' ); }); \/\/ ]]><\/script>[\/js]<\/p>\n<p><strong>Write your site URL in place of &#8220;SITE URL&#8221;.<\/strong><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Another one is for a particular link in your site. If you want to open a particular link of your site in a new tab. For that use a simple code in your header.php file just above the &lt; \/head&gt; mentioned below:-<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>[js]<script type=\"text\/javascript\">\/\/ <![CDATA[ jQuery(document).ready(function($){ $('#ClASS OF LINK').each(function(){ if( $(this).attr('href') &#038;&#038; 0 != $(this).attr('href').indexOf('#') ) { $(this).attr('target', '_blank'); } }); }); \/\/ ]]><\/script>[\/js]<\/p>\n<p><strong>Write the particular class of link in place of &#8220;#ClASS OF LINK&#8221;.<\/strong><\/p>\n<p>We are always available to solve any query related to the plugin. Hopefully, this post is helpful to you. For more queries visit our support forum.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lots of plugins are available to open links in a new tab but every time using a plugin is not good. So here I am giving you a simple and easy solution to open link in a new tab using coding. Just follow the instructions given below:- As you have external links in your site [&hellip;]<\/p>\n","protected":false},"author":7288,"featured_media":0,"template":"","meta":{"footnotes":""},"class_list":["post-8286","docs","type-docs","status-publish","hentry","docscate-custom-code","docstag-link","docstag-plugin","docstag-site","docstag-wordpress"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/docs\/8286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/users\/7288"}],"version-history":[{"count":1,"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/docs\/8286\/revisions"}],"predecessor-version":[{"id":69425,"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/docs\/8286\/revisions\/69425"}],"wp:attachment":[{"href":"https:\/\/themehunk.com\/fr\/wp-json\/wp\/v2\/media?parent=8286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}