4

What's the difference between:

bloginfo('name');

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.

3 Answers 3

7

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.

1
  • Thanks, that was simple. I should start looking more into the source code from now (should have done that first before asking, sorry).
    – Bobby
    Nov 13, 2013 at 3:49
1

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.

2
  • Noted, thanks. I actually knew about this. Didn't realize what I asked could be so easily misunderstood, sorry. The ticked answer was what I was asking for.
    – Bobby
    Nov 13, 2013 at 4:01
  • "The parameter is just an example" - I think that was the reason of misunderstanding. Nov 13, 2013 at 6:37
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.