[英]WordPress: the_content filter on the front-page.php
Any idea why the_content filter
is not being applied when front-page.php
file in use? 知道为什么在使用
front-page.php
文件时为什么不应用the_content filter
?
The code below in not getting executed when front-page.php
in use; 下面的代码在使用
front-page.php
时不会执行; works with index.php, page.php etc..
与
index.php, page.php etc..
function some_filter_name($content){
echo "dummy text";
return $content;
}
add_filter( 'the_content', 'some_filter_name' );
the_content()
on the page.
the_content()
。
the_content
filter is only applied on the_content
element - ie you have to use this in your template
the_content
过滤器仅应用于the_content
元素-即您必须在模板中使用它
I think this might be because in front-page.php you don't call the proper hook. 我认为这可能是因为在front-page.php中您没有调用适当的钩子。
In wordpress the add_filter
function hooks a function to a specific filter action. 在wordpress中,
add_filter
函数将函数挂钩到特定的过滤器动作。
An example of filter action is the_content
but this filter action needs to exist in any page that you want to use the custom function for. 过滤器动作的一个示例是
the_content
但是此过滤器动作需要存在于您要使用自定义函数的任何页面中。
Examples that you should have in your front-page.php
that the add_filter can use to hook your custom function: 您应该在
front-page.php
中拥有add_filter可以用来挂接自定义函数的示例:
<?php the_content('Read more...'); ?>
and 和
<?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...");
?>
Make sure that in front-page.php
you call the_content
hook and that the post/page/cpt content is displayed then you function callback should fire too, if not then the issue is not from the hook and needs extra debug. 确保在
front-page.php
调用the_content
钩子,并显示post / page / cpt内容,然后函数回调也应触发,如果不是,则问题不是来自钩子,需要额外的调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.