2013-10-16 2 views
1

front-page.php 파일을 사용할 때 the_content filter이 적용되지 않는 이유는 무엇입니까?WordPress : 앞 페이지의 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'); 


UPDATE와 함께 작동합니다 : 당신이 실제로 페이지에 the_content()를 사용하고 있는지 확인하십시오. the_content 필터 만 the_content 요소에 적용됩니다 - 즉, 내가 이렇게하면 적절한 훅을 호출하지 않기 때문에 전면 page.php에있을 수 있습니다 생각 템플릿

답변

2

이를 사용해야합니다.
wordpress에서 add_filter 함수는 함수를 특정 필터 동작에 연결합니다.
필터 동작의 예는 the_content이지만이 필터 동작은 사용자 지정 기능을 사용하려는 페이지에 존재해야합니다.

당신이 add_filter 사용자 정의 함수를 후크하는 데 사용할 수있는 귀하의 front-page.php에 있어야한다 예 : front-page.php 당신이 the_content 훅하고 있음을 부르는

<?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..."); 
?> 

가 있는지 확인 post/page/cpt 내용이 표시되면 함수 콜백이 실행되어야합니다. 그렇지 않으면 문제가 후크에서 발생하지 않고 추가 디버그가 필요합니다.

관련 문제