[英]Wordpress - PHP Fatal error: Call to undefined function get_bloginfo()
[英]How to override a get_bloginfo function in wordpress
function custom_get_bloginfo( $show = '', $filter = 'raw' ) {
switch( $show ) {
case 'description':
$output = "my description";
break;
default:
$output = get_option('blogname');
break;
}
return $output;
}
add_filter('get_bloginfo', 'custom_get_bloginfo', 1, 2);
我用上面的代碼不起作用..
get_bloginfo函數支持兩個過濾器,但前提是第二個參數“ filter”設置為“ display”,即
get_bloginfo('name', 'display');
因此,如果您希望將此插件用於某些插件,它將不會有太大用處。
可以使用的過濾器:
用法:
add_filter('bloginfo_url', 'custom_get_bloginfo', 10, 2);
add_filter('bloginfo', 'custom_get_bloginfo', 10, 2);
function custom_get_bloginfo($output, $show) {
switch( $show ) {
case 'description':
$output = 'my custom description';
break;
case 'name':
$output = 'custom name';
break;
}
return $output;
}
更新:如果您只希望替換站點描述,則可以執行以下操作:
add_filter('option_blogdescription', 'custom_option_description', 10, 1);
function custom_option_description($value) {
return 'custom description';
}
好的,現在我了解了,更好的方法是編輯header.php並查找bloginfo('description'),然后使用custom_get_bloginfo()進行更改,然后將其添加到function.php中。
function custom_get_bloginfo(){
switch( $show ) {
case 'description':
$output = "my description";
break;
default:
$output = get_option('blogname');
break;
}
return $output;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.