Jan
28
2009

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.

If you liked this, please share it.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , ,

Short URL: http://bit.ly/9PuhtS

Discussion 10 Comments

  1. Sean on February 20, 2009 at 4:48 pm

    How do I edit the font color for the bloginfo description that shows up at the top of my page?

    • c.bavota on February 20, 2009 at 4:53 pm

      Hey Sean,

      You have to edit that in your theme’s style.css file and add your colours and styles there. If you send me a link to your site I can get more specific with what exactly you need to do.

  2. basmin on March 28, 2009 at 6:34 pm

    hi. informative article

  3. honlapk?©sz??t?©s on June 7, 2009 at 3:28 pm

    Well…..I agree with most of the things you said. Anyway, thanks!

  4. kl??ma on June 7, 2009 at 3:30 pm

    Thanks for sharing this useful info.

  5. Jay Martin on August 4, 2009 at 7:42 am

    I’ve been looking for an explaination of these basic tags. Thanks for your help. Maybe now I can modify my theme.

  6. Roza on September 24, 2009 at 10:31 am

    Very interesting information that might be developed again, thank you i get good article

  7. openmtl on October 29, 2009 at 4:22 am

    There is one little gotcha – Other than displaying text you can’t assume bloginfo() is like echoing a string in functions e.g. parse_url(bloginfo(‘template_url’)) will just never work, but you must use get_bloginfo(‘template_url’).

  8. Marjory Gahan on December 11, 2009 at 8:22 am

    Advantageously, the article is in reality the sweetest on this laudable topic. I fit in with your conclusions and will eagerly look forward to your upcoming updates. Saying thanks will not just be adequate, for the great clarity in your writing. I will at once grab your rss feed to stay informed of any updates. Pleasant work and much success in your business dealings!

  9. Custom Name Badges on February 25, 2010 at 12:32 pm

    very useful article on wordpress Bloginfo object

Leave a Reply

Your email address will not be published. Required fields are marked *

*


To enter code in the comment box, please place it between <pre lang="php"> </pre> tags. You don't have to convert any characters to their hex/HTML code. Just add your code the way you would to any code editor.