简体   繁体   English

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

[英]How to Add a filter to single.php only in wordpress?

I want to add nofollow rel to tag cloud on single post only. 我只想在单篇文章中添加nofollow rel来标记云。 This function code in functions.php works fine but I couldn't figure it out how to restrict it to single.php only. 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');    

Could you please tell me how to do it?? 你能告诉我怎么做吗?

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

Should do the trick, remember to use it inside the function itself as I don't think WordPress knows if it's true/false while parsing functions.php 应该做到这一点,请记住在函数内部使用它,因为我不认为WordPress在解析functions.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');    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM