Tag Archives: bloginfo

New Tip! Upgrade-Proof Your Site with the bloginfo() Tag

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

Running against this is the necessity of putting full URL paths to images and files in the custom_functions.php file. If you use a lot of images from your /custom/images folder, it can be a real pain going through the file updating the URLs.

But you really don’t have to do that — not if you use the WordPress bloginfo() tag!

The article Upgrade-Proof Your Site with the bloginfo() Tag in the “Tips” section shows you how to use the tag to automatically put your Thesis path into URLs. That means that no matter what your Thesis folder is named, your URLs will always be up-to-date!

If you do a lot of work in the custom_functions.php file, this article is for you!

Upgrade-Proof Your Site with the bloginfo() Tag

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.