Generate Link to Wordpress Home Page with the bloginfo Function
Problem
Most Wordpress developers will develop their theme locally and then move it to a production server once it’s ready to launch the site. A problem can arise when you want to generate links to your blogs homepage on the dev site and then when you move to the production server, your links all break. Also, if you move your blog into another directory or subdomain for some reason, your links can also break.
Solution
Rather than hard coding your home page url into your theme pages, you can use the bloginfo() function to instead load the blog url that you entered into the Wordpress Admin section, that way you’ll always load the correct link.
So wherever you want to load your blog’s home page url, instead of hard coding the url, use this piece of PHP code:
<?php bloginfo('url'); ?>
This should hopefully help prevent some headaches when developing a theme that will eventually be located at different domains.
Related posts:








