2

我正在寻找一个选项,可以在新窗口中自动打开从我的网站(wordpress-blog)到任何其他网站的每个外部链接。是否可以使用 css 或 html 手动作为“目标 _blank”手动执行 1000 次?

太感谢了!

PS:对不起我的英语不好,我不是母语人士:(

4

3 回答 3

3

将此代码放在您的主题 functions.php 文件中。

function cdx_handel_external_links() {
    ?>
<script type="text/javascript">
( function( $ ) {

    $("a[href^=http]").click(function(){
      if(this.href.indexOf(location.hostname) == -1) {
         $(this).attr({
            target: "_blank"
         });
      }
    })

   //Add Nofollow
   $("a").each(function(){
    if(this.href.indexOf('nytimes.com') >0 ){
        $(this).attr({
            rel: "nofollow"
         });
    }
   });

} )( jQuery );
</script>
   <?php
}
add_filter( 'wp_footer', 'cdx_handel_external_links', 999);
于 2017-01-26T13:55:50.380 回答
2

是的,您可以使用在新窗口插件中打开外部链接。

在新窗口中打开所有或特定的外部链接会很有帮助。

于 2017-01-26T13:36:43.870 回答
1

如果您将以下内容放在 HTML 的 head 标记中,则任何没有目标的 href 标记都应在新窗口中打开:

<head>
    <base target="_blank">
</head>
于 2017-01-26T13:35:57.330 回答