Reputation: 507
Scenario: need to add a function to wp_footer, need it to be an action so I can add_ / do_ / remove_ it, and it needs to receive variables.
Problem: add_action('wp_footer', 'myfunc')
does not accept variables. add_action()
instead takes priority and number of argument variables, so that you can utilize do_action('myfunc', $arg1, $arg2...)
to execute function myfunc($arg1, $arg2)
. But calling do_action('wp_footer')
from a shortcode in the middle of your page is quite destructive!
Question: is there a better way to add actions, or is my approach just totally flawed and need revising?
Upvotes: 0
Views: 2170
Reputation: 507
Far better off to create a unique function that accepts your required variables, then add that as an action to wp_footer.
Upvotes: 1