问题
I was trying to edit my wordpress site name and description, I got that I have to add a filter plugin like so: add_filter( 'bloginfo', 'My_function_name', 10, 2 );
.
It works, but I can't understand why we have to add the 10, 2
parameters? and which values it belongs to?
Also there wasn't enough information in codex.wordpress.org
Here is my working plugin :
function edit_bloginfo($text,$show ){
if (isset($_COOKIE['switch_language'])) {
if($show == 'description'){
$text = 'New description';
}
if($show == 'name'){
$text = 'New site name';
}
return $text;
}
}
add_filter( 'bloginfo', 'edit_bloginfo', 10, 2 );
回答1:
In add_filter( 'filter_hook', 'your_function', 10, 2 );
expression, the 10, 2
parameters are:
- the first: the priority of your filter function during the execution of all filter functions. it is a number between 1 and ∞ ( use a reasonable one : ) ), many thanks to @brasofilo: look here.
- the latest: the number of parameters that will be passed to your function. The number of parameters declared and the number of parameters passed has to be the same.
Take a look to WordPress Codex Plugin API
Hope it helps!
来源:https://stackoverflow.com/questions/18675643/wordpress-bloginfo-filter-name-and-description