php
  • wordpress
  • themes
  • wordpress-theming
  • 2012-09-26 53 views 0 likes 
    0

    我想将nofollow rel添加到单个帖子上的标签云中。 functions.php中的这个函数代码工作正常,但我不知道如何将其限制为single.php。如何在wordpress中添加一个过滤器到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

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

    应该做的伎俩,记得使用它本身的功能,因为我不认为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');  
    
    +0

    我已经尝试过的真/假内已经重新尝试过了。单个帖子显示具有nofollow属性的标签云,但在所有其他页面(包括首页和归档页面)上,标签云隐藏/未显示。 –

    +0

    @AamirUsman:但你已经问过关于single.php的具体内容,所以你的评论看起来像你问的那样。请让自己对Wordpress页面层次结构更加熟悉:http://codex.wordpress.org/Template_Hierarchy – hakre

    +0

    好了,朋友,它隐藏了整个云(整个小部件)。而我想在single.php上添加nofollow,并在其他页面上删除nofollow。我想保留所有页面上的小部件。我希望你现在明白。 –

    相关问题