php
  • wordpress
  • themes
  • wordpress-theming
  • 2012-09-26 54 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。我想保留所有頁面上的小部件。我希望你現在明白。 –

    相關問題