之前我们尝试把评论者链接在新窗口打开《wordpress评论者链接在新窗口打开》,今天我们学习怎么去除评论作者的链接和回复链接,对于优化优化来说,这些评论链接占用了抓取时间,但是却没有什么优化效果。
去除方法很简单,我们只需要在函数文件functions.php文件中添加以下两段代码即可:
1、为评论者链接添加nofollow属性:
- //为评论者添加nofollow属性
- function add_nofollow_to_comments_popup_link(){
- return 'rel="nofollow" ';
- }
- add_filter('comments_popup_link_attributes', 'add_nofollow_to_comments_popup_link');
2、为评论回复添加nofollow属性:
- //为评论回复链接加nofollow属性
- add_filter('comment_reply_link', 'add_nofollow_to_replay_link');
- function add_nofollow_to_replay_link( $link ){
- return str_replace( '")\'>', '")\' rel=\'nofollow\'>', $link );
- }
3、添加完成后,记得保存覆盖,然后查看效果。
老师问什么我复制这代码 评论中实现不了屏蔽评论中的链接呢
只是添加了nofollow值。