I am developing a plugin.
I want to know difference between
get_bloginfo('url');
and
get_site_url();
I got same output, then what’s the difference?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
-
get_bloginfo('url')callshome_url()callsget_home_url()reads optionhome -
get_bloginfo('wpurl')callssite_url()callsget_site_url()reads optionsiteurl get_bloginfo('siteurl')andget_bloginfo('home')are deprecated arguments and returnget_bloginfo('url')(siteurlargument is documented wrong in Codex as equal towpurl, it’s not in current code)
The difference is that these two function chain to different options, which are typically same.
It would be more appropriate to compare get_bloginfo('url') to get_home_url() or get_bloginfo('wpurl') to get_site_url(). Then the answer is that these functions are on different level in chain. Typically the deeper function is – the more flexible it is and the less filters output passes through.
Method 2
From ‘wp-includes/general-template.php’
function get_bloginfo( $show = '', $filter = 'raw' ) {
switch( $show ) {
case 'home' : // DEPRECATED
case 'siteurl' : // DEPRECATED
_deprecated_argument([snipped]);
case 'url' :
$output = home_url();
break;
case 'wpurl' :
$output = site_url();
break;
So:
get_bloginfo('home'),get_bloginfo('siteurl')andget_bloginfo('url')are equivalent to callinghome_url()(also note that the use of home and siteurl as get_bloginfo parameters is deprecated)get_bloginfo('wpurl')is the same as callingsite_url()
Method 3
Check out the parameters over at Codex:
Method 4
IIRC, the primary difference between home_url()/get_site_url() and their get_bloginfo() analogs is that home_url()/get_site_url() return the proper http/https scheme, while get_bloginfo() doesn’t.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0