网站的外链安全是个很重要的事情,因为很多外链网站消亡的比较快,然后如果被人做成了有害身心健康的网站...
对于我们广大的Wordpress博客来说,文章里的外链一般应该问题不大,主要的不稳定外链源就是评论了,基本所有博客都支持评论者留下网址。这就要注意了,特别是你网站评论留言用户非常多的话。
那么,对于我们 WordPress 博客来说,怎么杜绝这种事情呢?
方法一
/** * 不显示 WordPress 评论列表里超过 N 天的评论者的网站链接 - 龙笑天下 * http://www.ilxtx.com/remove-comment-author-url-over-certain-days.html */ function lxtx_filter_hide_comment_url( $url, $comment_id, $comment ) { if ( empty($url) || empty($comment->comment_ID) || current_user_can('manage_options') ) { return $url; } $days = 365;// 删除多少天前的评论的链接,默认 365 天,可自行修改 if ( time() - strtotime($comment->comment_date) > $days*24*3600 ) { $url = ''; } return $url; } add_filter('get_comment_author_url', 'lxtx_filter_hide_comment_url', 10, 3);
方法二
/** * 不显示 WordPress 评论列表里超过 N 天的评论者的网站链接 - 龙笑天下 * http://www.ilxtx.com/remove-comment-author-url-over-certain-days.html */ function lxtx_filter_hide_comment_url($return, $author, $comment_ID){ date_default_timezone_set('PRC'); if ( current_user_can('manage_options') ) { return $return; } $comment = get_comment( $comment_ID ); if ( empty($comment->comment_author_url) ) { return $return; } $days = 365;// 删除多少天前的评论的链接,默认 365 天,可自行修改 if ( time() - strtotime($comment->comment_date) > $days*24*3600 ) { $return = $author; } return $return; } add_filter('get_comment_author_link', 'lxtx_filter_hide_comment_url', 10, 3);
任选 1 种方法,将代码放进主题的 functions.php 文件里,然后就对游客不显示超过 365 天的评论的网站链接了,天数自己代码里修改。
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!欢迎打赏!
评论