Using Bloginfo to Build a Custom Theme for WordPress

When you build a custom theme in WordPress that you would eventually like to share with the WordPress community, you can’t hard code certain elements like the blog’s name or images links. I know most coders use things like <a href="../link.php"> or <a href="images/pic.jpg"> but those might not work properly if your WordPress install is not in the root directory or if you are on a category page.

WordPress has a very useful tag that you might have seen around if you’ve ever taken a look at the source code of any theme. It’s called bloginfo and it solves a lot of problems for programmers. Here are some examples of how you would use it.

<?php bloginfo('name'); ?>
This will bring up the name of the blog as entered under the Settings => General page in the admin. This tag should be used when coding the header to display the name of the blog.

<?php bloginfo('description'); ?>
This will display the description of the blog as entered under the Settings => General page in the admin. This tag should be used somewhere in the header to display the blog’s description.

<?php bloginfo('url'); ?>
This will get you the URL of where WordPress has been installed, no matter if it’s in the root directory or a sub-directory. This is great for linking to certain pages or to link back to the home page.

<?php bloginfo('template_url'); ?>
This tag is a life saver when developing custom themes. It brings back the location of where your custom theme’s folder has been installed. Life became a whole lot easier when I discovered this tag. It’s extremely useful when developing a custom theme if you need to link to a secondary stylesheet or display an image stored in the images directory of your custom theme.

Small Biz Website Tips Newsletter

Stay up to date with the latest marketing, sales, and service tips and news.