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.

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie