[英]WordPress: the_content filter on the front-page.php
知道为什么在使用front-page.php
文件时为什么不应用the_content filter
?
下面的代码在使用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
元素-即您必须在模板中使用它
我认为这可能是因为在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内容,然后函数回调也应触发,如果不是,则问题不是来自钩子,需要额外的调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.