我刚刚开始学习Wordpress并通过标准/默认主题。如果我已经正确理解了过滤器的想法,那么在我们应用它们之前,我们需要通过add_filter($hook, $callback, $args)
添加回调函数。然而,看着“二十七岁”。主题我无法看到twentyseventeen_starter_content
的声明,然后使用它:$starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
(文件functions.php)和twentyseventeen_front_page_sections
- $num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
(文件正面 - page.php文件)。我缺少什么以及如何在不设置回调函数的情况下工作?
答案 0 :(得分:1)
apply_filters
runs all the callbacks attached to it by add_filter
to the same hook/tag. If there are no callbacks attached to that hook/tag it returns the second parameter (which is the value beng filtered) of the apply_filters
. Therefore apply_filters( 'twentyseventeen_front_page_sections', 4 );
will return 4 if there are no add_filter('twentyseventeen_front_page_sections', 'callbackfunc');
. Else it will return the result of the add_filter callback with the highest priority after going through all callbacks.
Priorities are set in the add_filter
as the third parameter.
I don't know if this what you were looking for but i thought it might give you a better understanding.