How many times can I hook into the same action?

WordPress hooks work like Hollywood: you don’t call them, they call you. But unlike Hollywood, they keep calling everyone on the list.

It’s normal for an action or a filter to have multiple functions hooked to it, from different plugins, or even just different functions in the WordPress core that all do something specific. It is not only possible, but even good practice, as it means your code gets clearer (each function does only one thing) and it’s easier to disable one specific piece of functionality by unhooking it.

Remember that you can also play with the priorities of hooks: if you want to run both functionA() and functionB() in the after_setup_theme, but functionA() must run before functionB(), you can hook functionA() with the default priority 10 and functionB() with priority 20 (or any other number above 10). What won’t work is hooking another function to an action while that action is executing. So you can’t hook functionB() to after_setup_theme from functionA(), called on after_setup_theme. You could call it directly, but you would lose the benefit of separate hooks.

Leave a Comment