Products
GG网络技术分享 2025-03-18 16:12 3
I\'ve just started learning Wordpress and going through standard/default themes. If i have understood filters idea correctly, before we can apply them we need to add callback functions via add_filter($hook, $callback, $args)
. However looking at the \'twentyseventeen\' theme i can\'t see those declaration for twentyseventeen_starter_content
and it is used then with: $starter_content = apply_filters( \'twentyseventeen_starter_content\', $starter_content );
(file functions.php) and twentyseventeen_front_page_sections
- $num_sections = apply_filters( \'twentyseventeen_front_page_sections\', 4 );
(file front-page.php). What am i missing and how does it work without setting callback functions?
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我刚刚开始学习Wordpress并浏览标准/默认主题。 如果我已正确理解过滤器的想法,在我们应用它们之前,我们需要通过 add_filter($ hook,$ callback,$ args)</ code>添加回调函数。 然而,看看\'二十七\'主题,我无法看到
twentyseventeen_starter_content </ code>的声明,然后使用它:
$ starter_content = apply_filters(\'twentyseventeen_starter_content\',$ starter_content); </ code >(file functions.php)和
twentyseventeen_front_page_sections </ code> -
$ num_sections = apply_filters(\'twentyseventeen_front_page_sections\',4); </ code>(file front-page.php)。 我缺少什么,如果没有设置回调函数它是如何工作的?</ p>
</ div>
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.
Demand feedback