2013-10-16 58 views
1

任何想法爲什麼the_content filter沒有被應用當front-page.php文件在使用?WordPress的:front_page.php上的the_content過濾器

下面的代碼在front-page.php正在使用時未得到執行;與index.php, page.php etc..

function some_filter_name($content){ 

    echo "dummy text"; 
    return $content; 

} 
add_filter('the_content', 'some_filter_name'); 


更新工作:確保你實際上是在頁面上使用the_content()the_content過濾器僅應用於the_content元素 - 即您必須在您的模板中使用此過濾器

回答

2

我認爲這可能是因爲在front-page.php中,您不會調用正確的掛鉤。
在wordpress中,add_filter函數將函數掛鉤到特定的過濾器操作。
篩選器操作的一個示例是the_content,但此篩選器操作需要存在於您要使用自定義函數的任何頁面中。

,你應該在你的front-page.php了的add_filter可以使用掛鉤自定義函數的例子:

<?php the_content('Read more...'); ?> 

<?php 
global $more; // Declare global $more (before the loop). 
$more = 0;  // Set (inside the loop) to display content above the more tag. 
the_content("More..."); 
?> 

確保在front-page.php你打電話the_content鉤的顯示post/page/cpt內容,那麼你的函數回調也應該觸發,如果沒有,那麼問題不是來自鉤子,需要額外的調試。

相關問題