Question about filter / action priority
-
in my main plugin I filter the_content to add rich snippet, something like this:
favorite in my main plugin I filter the_content to add rich snippet, something like this: add_filter('the_content', 'add_schema'); function add_schema($content) { $schema=NULL; //To avoid undefined variable notice outside the loop $review_choosen = get_snippet_type(); //Use apply filter to allow users to customize the rich snippet $schema = apply_filters( 'filter_schema_microdata', $review_choosen ) //If $schema is not false mean the user added his filter and return this one if ($schema) { return $content . $schema; } //DEFAULT CODE HERE }At the begin of the function, I use apply_filter to let my user or other developer to customize the rich snippet instead use the defaults that my plugin adds.
If the add_filter is put on functions.php, everything is ok.
But now I’m working on an extension that run on plugins_loaded. So when I try to use add_filter here this is what happens:
If I use
add_filter ( 'filter_schema_microdata', 'callback_function' ) function callback_function ($review_choosen) {the $review_choosen var is empty.
If instead, I try to put an higher priority, e.g. 9
add_filter ( 'filter_schema_microdata', 'callback_function', 9 ) function callback_function ($review_choosen) {The $review_choosen var is ok, but the functions doesn’t return nothing.
So in which action should I run the add_filter?
The topic ‘Question about filter / action priority’ is closed to new replies.