If a theme and a plugin uses the same action hook, for example comment_form
is used by both theme and plugin. Then , which one will be called first? the function associated with the theme’s hook or the function associated with the plugin’s hook.
2 comments
Comments are closed.
An action hook is simply a queue point that acts at a specific point in the PHP execution process: callbacks are queued via
add_action()
call, and everything in the queue gets processed in turn:A filter hook is a similar queue point, only it acts on a specific bit of data – it could be a string, an array, an integer, or whatever. As with actions, callbacks are queued via
add_filter()
call, and everything in the queue gets processed in turn.If you need to ensure that one callback gets processed earlier or later than another, then you will need to ensure that the two callbacks have different priorities. The lower the number, the higher the priority, and the earlier the execution. The default priority is
10
, so anything added with a priority of11
will execute after the default, and anything added with a priority of9
will execute before the default.So, yes: both the Theme and Plugins can add action or filter callbacks to the same action/filter hook, without conflict.
Every
action/filter
hooks have a priority parameter(the third parameter). The default value of which is10
, the lesser the value the earlier it is calledLike
add_action( $tag, $function_to_add, $priority, $accepted_args );
add_filter( $tag, $function_to_add, $priority, $accepted_args );