简体   繁体   English

WordPress:front-page.php上的the_content过滤器

[英]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' );


UPDATE: Make sure you are actually using 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM