Upgrade-Proof Your Site with the bloginfo() Tag

by Mike Nichols · 4 comments

Thesis has the reputation of being upgrade-proof. That is, you do not lose your work in the custom folder when you upgrade.

However, custom_functions.php and widgets require that you to enter the full file path to files and images. When you upgrade, you have to go back and change every full path to that of your new upgraded Thesis folder.

Or do you? Not if you use the WordPress tag bloginfo().

What is the bloginfo() tag?

We sometimes forget that WordPress has many functions and tags that are available for us to use, and bloginfo() is one of them.

The bloginfo() tag provides a great deal of information when used with its parameters, ranging from the title of the post or page, to the URL of the site’s feed. A full list of the parameters can be found on the WordPress Codex page for bloginfo().

The parameters we are looking at in this article are those that give you various file paths to your Thesis folder. The following list shows these, along with an example:

  • bloginfo(‘url’) = http://thesisthemetools.com
  • bloginfo(’stylesheet_directory’) = http://thesisthemetools.com/wp-content/themes/thesis_151
  • bloginfo(’stylesheet_url’) = http://thesisthemetools.com/wp-content/themes/thesis_151/style.css
  • bloginfo(‘template_directory’) = http://thesisthemetools.com/wp-content/themes/thesis_151
  • bloginfo(‘template_url’) = http://thesisthemetools.com/wp-content/themes/thesis_151

Note that none of the file paths have a trailing forward slash (/). Three of the parameters give essentially the same information: stylesheet_directory, template_directory, and template_url.

How to use bloginfo() in file paths

Essentially, you substitute the bloginfo() tag for the portion of the file path you want replaced. The basic syntax is:

	<?php bloginfo('PARAMETER'); ?>

For example, here is a full file path that might be used in custom_functions.php or a widget:

	<img src= "http://thesisthemetools.com/wp-content/themes/thesis_151/custom/images/icon-rss.gif" alt="RSS"/>

When I upgrade Thesis I would have to go back to my custom_functions.php file or widget and change this URL. But if I use bloginfo() with the “template_url” parameter, the new URL will be automatically picked up, like so:

	<img src= "<?php bloginfo('template_url'); ?>/custom/images/icon-rss.gif" alt="RSS"/>

The bloginfo() tag is a direct substitute for the file path. There is no need to put quotes around it.

Note that these examples have the PHP beginning and ending tags for use whenever PHP is not active. Of course, if PHP is active, you would leave them out.

How to use bloginfo() in widgets

Widgets can use bloginfo() too, but you have to have a plugin that provides PHP functionality in widgets. My favorite is Exec-PHP available from the WordPress plugins page or from the author’s plugin page.

All you have to do is download and activate the plugin and you have PHP functionality within your widgets (and posts, too). The method of using bloginfo() is the same as described above.

Conclusion

I encourage you to have a look at the bloginfo() page in the WordPress codex. The tag has many parameters that you can use to save you a lot of time and effort.

I hope this article has been helpful to you. Remember that your comments are always welcome, and that you can email me directly by clicking on the “Contact” button in the menu.

Share and Enjoy:
  • StumbleUpon
  • Digg
  • del.icio.us
  • Technorati
  • Facebook
  • MySpace
  • FriendFeed
  • Sphinn
  • LinkedIn
  • Twitter
  • email
  • Print
  • PDF
Related Articles

{ 1 trackback }

New Tip! Upgrade-Proof Your Site with the bloginfo() Tag | Thesis Theme Tools
October 17, 2009 at 3:32 pm

{ 3 comments… read them below or add one }

Ted Hessing January 8, 2010 at 8:22 pm

Neat solution, Mike. I punted and put directories at root for some sites, and went by reference for others. (Hoping Chris doesn’t change the folder structure again!)

I found bloginfo() really helpful when I built my first Thesis-custom code – a mod that created a dynamic photo gallery in a post when you included a variable with the path name as the value.

Ok, enough chit-chat! I’ve gotta go try out that neat contextual sub menu tip you provided! Love the site, thanks for the tips. Just added you to a Google Reader folder along side Kristarella, et al.

Reply

Ted Hessing January 8, 2010 at 8:23 pm

PS I don’t suppose you’re feeling generous enough to write up a tip about your cool footer?

Reply

Ted Hessing January 8, 2010 at 8:29 pm

OK, I’m slow. You have it under Fat Footer! Please delete this and prior comment.

Reply

Leave a Comment

  • Visit My Other Site!