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.
The two functions output exactly the same thing.
From the Codex entry for
get_bloginfo()
:From source:
Neither
get_bloginfo()
norbloginfo()
do any sort of sanitization or escaping; so bothget_bloginfo( 'name' )
andget_option( 'blogname' )
return exactly the same value.First of all,
bloginfo
will output value 😉 If you want to get the value, you should useget_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 casebloginfo
returns value of that option).On the other hand,
get_option
can be used to retrieve value of any option stored in options table.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 theoptions.php
the link for theoptions.php
ishttp: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