WordPress 评论者超链接实现重定向跳转的方法

2019-02-19 19:20:25于丽


这点是在万戈 那里看来的,说是如果使用了 cos-html-cache 静态化插件,会导致 Comments Link Redirect 插件无法正常使用,yanxc 给出了一个解决方案,专门针对使用了 cos-html-cache 静态化插件的朋友。

方法同样是把以下代码复制到你使用的主题文件中的 functions.php 文件里面,代替上面提供的代码。


//comments link redirect
add_filter('get_comment_author_link', 'add_redirect_comment_author_link', 5);
add_filter('comment_text', 'add_redirect_comment_text', 99);
function add_redirect_comment_author_link($text = ''){
$text=str_replace("href=",'href="javascript:window.location=',ereg_replace('href='[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]'',"0"", $text));return $text;
}
function add_redirect_comment_text($text = ''){
$text=str_replace("href=","href='javascript:window.location=",ereg_replace('href="[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]"',"0'", $text));return $text;
}

然后再修改 robots.txt 文件即可。
使用 mg12 的 inove 主题不能实现链接重定向跳转的解决方法

有博友反映说使用 inove 主题通过以上的两种方法都不能实现评论区的链接重定向跳转,经过园子研究解决方法其实也很简单,方法如下:

打开 inove 主题目录下的 functions.php 文件,查找类似如下代码:
<a id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php comment_author_url() ?>" rel="external nofollow">
将其改成:

<a target="_blank" id="commentauthor-<?php comment_ID() ?>" class="url" href="https://www.jb51.net/?r=<?php comment_author_url() ?>" rel="external nofollow">
改完代码后,再使用上面提供的基于插件或修改代码的方法即可完美实现重定向跳转的效果。

这两种方法的最终目的其实都是在和垃圾评论做战,虽然不能通过此方法杜绝垃圾评论,但如果那些发垃圾评论的人得不到丝毫的权重和价值,对他们来说也就没有什么意义了。