2014-01-12 72 views
0

如何將rel =「nofollow」添加到具有時間標記的鏈接中,在comment-metadata div內部?add rel =「nofollow」to comment_metadata

<div class="comment-metadata"> 
<a href="http://localhost/wordpress/hello-world/#comment-2"> 
<time datetime="2013-12-22T10:43:03+00:00">...</time> 
</a> 
</div> 


    function add_nofollow_to_comment_metadata($link) { 
     return str_replace('")\'>', '")\' rel=\'nofollow\'>', $link); 
    } 

    add_filter('comment_comment_metadata', 'add_nofollow_to_comment_metadata'); 

我使用<?php wp_list_comments(); ?>沒有任何自定義。

回答

0

你並不需要添加代碼 WordPress會自動nofollow的評論鏈接

+0

如果wordpress這樣做,爲什麼我問這個問題? :) – newbie

1

沒有辦法修改通過鉤子或過濾器這種行爲。但您可以通過以下方式實現:

  1. 使用get_comments函數。它允許最大限度的定製。
  2. 擴展Walker_Comment類並實現您的自定義功能。

第一個選項顯然比較簡單。