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?
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.