{"id":54710,"date":"2018-05-25T15:35:57","date_gmt":"2018-05-25T18:35:57","guid":{"rendered":"https:\/\/samuelchopard.ch\/wiki\/?p=54710"},"modified":"2024-12-17T11:15:48","modified_gmt":"2024-12-17T10:15:48","slug":"make-all-external-links-open-in-a-new-tab","status":"publish","type":"post","link":"https:\/\/samuelchopard.ch\/wiki\/library\/make-all-external-links-open-in-a-new-tab\/","title":{"rendered":"Make all external links open in a new tab"},"content":{"rendered":"<p><!--more--><\/p>\n<p>Paste the following in <strong><em>functions.php<\/em><\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\">\/* Make all external links open in a new tab *\/\r\nfunction autoblank($text) {\r\n$return = str_replace('target=\"_blank\" href=', 'target=\"_blank\" target=\"_blank\" href=', $text);\r\n$return = str_replace('target=\"_blank\" target=\"_blank\" href=\"http:\/\/domain.com', 'target=\"_blank\" href=\"http:\/\/domain.com', $return);\r\n$return = str_replace('target=\"_blank\" href=\"#', 'href=\"#', $return);\r\n$return = str_replace('>', '>', $return);\r\nreturn $return;\r\n}\r\nadd_filter('the_content', 'autoblank');\r\nadd_filter('comment_text', 'autoblank');\r\n<\/pre>\n<p>Replace <em>domain.com<\/em> with the actual domain of your site.<\/p>\n<p><strong>Note:<\/strong> &#8220;internal&#8221; links should be written in full, not just the extension (&#8220;<em>samuelchopard.ch\/wiki<\/em>&#8221; and not &#8220;<em>\/wiki<\/em>&#8220;), if not, &#8220;internal&#8221; links will be opened in a new tab as well.<\/p>\n<p>Source: <a target=\"_blank\" href=\"https:\/\/wjekoslaw.wordpress.com\/2013\/07\/03\/making-all-external-links-open-in-a-new-tab-in-wordpress\/\">https:\/\/wjekoslaw.wordpress.com\/2013\/07\/03\/making-all-external-links-open-in-a-new-tab-in-wordpress\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Paste the following in functions.php: \/* Make all external links open in a new tab *\/ function autoblank($text) { $return [...]","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[105,161,192],"class_list":["post-54710","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-external-links","tag-links","tag-new-tab"],"_links":{"self":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/comments?post=54710"}],"version-history":[{"count":9,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54710\/revisions"}],"predecessor-version":[{"id":55205,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54710\/revisions\/55205"}],"wp:attachment":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/media?parent=54710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/categories?post=54710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/tags?post=54710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}