我想在单个帖子上添加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');
你能告诉我怎么做吗?
答案 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');