I have been reading through Codex and other SO and SE posts regarding this. But I am confused.
I used home_url() and site_url() to linking the site’s home and it gave same results.
As I was using qTranslate for bilingual implementation. And had its language switcher.
Found later, when clicked on the home logo (used home_url()
and site_url()
) the current language didn’t persist. Because, I am using one language as default and which would just produce http://example.com And for other language it would be http://example.com/ar
Later I found that, using bloginfo('home')
solves it. The url now carries the language suffix with the home URL.
As these posts say the bloginfo() functions are being deprecated. I am really confused.
The difference in your case is in filters being applied to output of these functions.
While bloginfo applies one of these filters:
Function home_url applies this filter:
Adn finally site_url applies this filter:
It is true that bloginfo uses one of mentioned functions (home_url and site_url). It is clear from its source code:
From this piece of code, it is clear that when calling bloginfo(‘home_url’) or bloginfo(‘site_url’), all mentioned filters ale applied. When calling home_url or site_url, bloginfo’s filters are not applied.
The thing is, that qTranslate, probably, hooks only bloginfo’s filters.
Open your backend and go to Settings/General. You will see to input fields:
The first one correspond to
site_url()
and the second one tohome_url()
So why is there a difference? Because WordPress is able to start from a different site then your blog posts. For example, create a page called ‘homepage’ and enter in the second input field on Settings/General your domain and the pagename (with pretty permalinks turned on):
http://www.example.com/homepage
. From now on your blog starts with ‘homepage’ instead of the list with your blog posts. If a user enters ‘http:/www.example.com’ in the browsers adress bar, the ‘homepage’ page will be displayed (a memory hook:home_url()
shows you the homepage). In short, this feature is called ‘static frontpage’The site url is the ‘domain’ of your WordPress install no matter what page or site should be displayed as start page/frontpage/homepage.
bloginfo()
is just a wrapper forget_option()
. The parameterhome
is deprecated since version 2.2 in favor ofsiteurl
.wpurl
-> site_url()siteurl
-> home_url()Because this is confusing, it is better to use the function calls
site_url()
andhome_url()
To avoid using deprecated call
bloginfo('home')
added new function to qtranslate_core.php:and new filter to qtranslate_hooks.php:
This way no other changes were needed. Not the best solution but worked in my env. Hope qTranslate author won’t get mad for this.
Have to always use
home_url('/')
this way in themes/plugins to keep localization. Can be improved by using some special parameter instead of'/'
which won’t ever be used as real address.Tested on
WordPress 3.5.2
+qTranslate 2.5.35
+Responsive theme 1.9.3.2
.