bloginfo() vs get_option?

What’s the difference between:

bloginfo('name');

Read More

vs

get_option('blogname');

The parameter is just an example, but I see no differences in terms displaying what I want.

Are there any particular differences? Or are they just for semantic reasons.

Thanks in advance.

Related posts

3 comments

  1. The two functions output exactly the same thing.

    From the Codex entry for get_bloginfo():

    ‘name’ – Returns the “Site Title” set in Settings > General. This data is retrieved from the “blogname” record in the wp_options table.

    From source:

    case 'name':
    default:
        $output = get_option('blogname');
    

    Neither get_bloginfo() nor bloginfo() do any sort of sanitization or escaping; so both get_bloginfo( 'name' ) and get_option( 'blogname' ) return exactly the same value.

  2. First of all, bloginfo will output value 😉 If you want to get the value, you should use get_bloginfo.

    get_bloginfo takes one param from predefined set (You can find all possible values here: http://codex.wordpress.org/Function_Reference/bloginfo). Only part of these values are values of options (in such case bloginfo returns value of that option).

    Returns information about your site which can then be used elsewhere
    in your PHP code. This function, as well as bloginfo(), can also be
    used to display your site information anywhere within a template file.

    On the other hand, get_option can be used to retrieve value of any option stored in options table.

    A safe way of getting values for a named option from the options
    database table. If the desired option does not exist, or no value is
    associated with it, FALSE will be returned.

  3. bloginfo

    Displays information about your site, mostly gathered from the information you supply in your User Profile and General Settings WordPress Administration Screens. It can be used anywhere within a template file. This always prints a result to the browser. If you need the values for use in PHP, use

    get_bloginfo().

    Where as get_option() is far different from that, you can get any option from the options.php the link for the options.php is http:yoursite/wp-admin/options.php this display all the fields. you can get the value from
    $field_val = get_option('name_of_field');. For more about get_option refer codex get_option

Comments are closed.