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);

i used above code its not work..

Related posts

Leave a Reply

2 comments

  1. get_bloginfo function supports two filters but only if second argument “filter” is set to “display” i.e.

    get_bloginfo('name', 'display');
    

    So if you wish to use this for some plugin, it will not be of much use.

    Filters that can be used:

    • bloginfo_url (this one is for all options that return urls)
    • bloginfo

    Usage:

    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;
    }
    

    UPDATE:
    If you just wish to replace site description you can do this:

    add_filter('option_blogdescription', 'custom_option_description', 10, 1);
    function custom_option_description($value) {
        return 'custom description';
    }
    
  2. Ok I understand it now, the better way to do it is to edit your header.php and look for bloginfo( ‘description’ ) then change it with custom_get_bloginfo() then add you can use this to your function.php

    function custom_get_bloginfo(){
    switch( $show ) {
    case 'description':
    $output = "my description";
    break;
    
    default:
    $output = get_option('blogname');
    break; 
    }
    return $output;
    }