Answer the question
In order to leave comments, you need to log in
How to pass an argument to a callback function?
I have a variable that needs to be passed to a function, but I can't figure out how.
The wordpress documentation says that a variable can be passed in this way:
$var = 1;
function name($var) {echo $var;}
add_action('wp_head', 'name', 10, 1);
Answer the question
In order to leave comments, you need to log in
function filter_name($var){
if( /*бла бла бла */ ) {
$var = 1;
} elseif ( /*бла бла бла */ ) {
$var = 2;
} else {
$var = 3;
}
return $var;
}
add_filter('my_name','filter_name');
function name($var = '') {
echo apply_filters('my_name',$var);
}
add_action('wp_head', 'name', 10, 1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question