WordPress评论者主页链接新窗口打开
作者:dianso 发布时间:April 7, 2010 分类:存檔備份,談博說博
在虎头鱼那看到了通过修改 wordpress 文件的方法做到评论者主页链接新窗口打开,我嫌麻烦,于是放狗搜索了下,找到了个方法。
只需要把的下面的代码复制到主题的 function.php 中就可以了。
// Make comment author link URL open in new window function comment_author_link_window() { global $comment; $url = get_comment_author_url(); $author = get_comment_author(); if ( empty( $url ) || 'http://' == $url ) $return = $author; else $return = "<a href='$url' rel='external nofollow' target='_blank'>$author</a>"; return $return; } add_filter('get_comment_author_link', 'comment_author_link_window');
如果非要用标准的 external,那么我推荐这种方法,在 header.php 加入:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){$("a[rel='external'],a[rel='external nofollow']").click(function(){window.open(this.href);return false})}) </script>
然后 function.php 加入:
// Make comment author link URL open in new window function comment_author_link_window() { global $comment; $url = get_comment_author_url(); $author = get_comment_author(); if ( empty( $url ) || 'http://' == $url ) $return = $author; else $return = "<a href='$url' rel='external nofollow' rel='external'>$author</a>"; return $return; } add_filter('get_comment_author_link', 'comment_author_link_window');
Dianso‘s Blog