Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
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 '13 at 3:49
add comment

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.

share|improve this answer
    
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 '13 at 4:01
    
"The parameter is just an example" - I think that was the reason of misunderstanding. –  Krzysiek Dróżdż Nov 13 '13 at 6:37
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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