can I do something like that? to pass arguments to my function? I already studied add_action doc but did not figure out how to do it. What the exact syntax to pass two argum
Well, this is old, but it has no accepted answer. Reviving so that Google searchers have some hope.
If you have an existing add_action
call that doesn't accept arguments like this:
function my_function() {
echo 100;
}
add_action('wp_footer', 'my_function');
You can pass an argument to that function by using an anonymous function as the callback like this:
function my_function($number) {
echo $number;
}
$number = 101;
add_action('wp_footer', function() { global $number; my_function($number); });
Depending on your use case, you might need to use different forms of callback, possibly even using properly declared functions, as sometimes you may encounter trouble with scope.