如何在wordpress中添加过滤器到single.php?

时间:2012-09-26 06:05:52

标签: php wordpress themes wordpress-theming

我想在单个帖子上添加nofollow rel到标签云。 functions.php中的这个函数代码运行正常,但我无法弄清楚如何将它限制为single.php。

function szub_nofollow_tag($text) {
return str_replace('<a href=', '<a rel="nofollow" href=',  $text);
}


add_filter('wp_tag_cloud', 'szub_nofollow_tag');    

你能告诉我怎么做吗?

1 个答案:

答案 0 :(得分:1)

http://codex.wordpress.org/Function_Reference/is_singular

应该做的诀窍,记得在函数本身内部使用它,因为我不认为WordPress在解析函数时知道它是真还是假.php

function szub_nofollow_tag($text) {
    if ( is_singular() )
        return str_replace('<a href=', '<a rel="nofollow" href=',  $text);
    else
        return $text;
}


add_filter('wp_tag_cloud', 'szub_nofollow_tag');    
相关问题