老牛註釋:慎用此方法!在最新版本的 WordPress 上無效,還會導致網站出 500 錯誤,後台也無法進入,解決方法,登陸主機後台,使用在線文件管理器,在線編輯你所使用的模板目錄下 function.php,刪除添加的代碼即可恢復。
或許你已經找到生成評論鏈接的方法: comments_popup_link. 並準備如同處理 Read more 一樣為鏈接加上 nofollow, 但是最終發現這個方法不能使用 filter. 是的, 這個方式不能這樣搞, 三年前就有人認為這是一個 bug 了.
其實不然, 該方法在打印 a 標籤的 title 屬性前有以下語句:
echo apply_filters( ‘comments_popup_link_attributes’, ” );
什麼意思? 説明可以通過 comments_popup_link_attributes 為鏈接加上其他屬性. 所以我們可以在 function.php 或者在插件中加入以下代碼來為 WordPress 的評論鏈接加上 nofollow:
function add_nofollow_to_comments_popup_link(){
return ‘ rel=”nofollow” ‘;
}
add_filter(‘comments_popup_link_attributes’, ‘add_nofollow_to_comments_popup_link’);
通過為 WordPress 的評論鏈接加上 nofollow.