wordpress bloginfo filter name and description

孤人 提交于 2019-12-13 05:16:12

问题


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:

  1. 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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!