Home > Make Wordpress Do What You Want > Generate Link to Wordpress Home Page with the bloginfo Function

Generate Link to Wordpress Home Page with the bloginfo Function

August 18th, 2009 Leave a comment Go to comments

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.

The wordpress url is where you installed wordpress to on your server

The wordpress url is where you installed wordpress to on your server

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.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Design Float
  • Reddit
  • Technorati
  • StumbleUpon

Related posts:

  1. Fixing 404 Error When Using Wordpress Pretty Permalinks with WAMP
  2. Disabling Automatic Post and Page Formatting in Wordpress Themes
  3. Automatically Generate and Submit an XML Sitemap with Every Wordpress Post

  1. No comments yet.
  1. No trackbacks yet.