WordPress’ Bloginfo Explained

WordPress’ Bloginfo Explained

Posted on 23. Oct, 2009 by Alex Denning in Quick Tips

One of the most useful template tags you’ll use in WordPress is bloginfo. As the name suggests, it lets you dynamically show information about your blog. That’s the important bit. Your blog. So when you’re designing a theme for public release, you can accommodate for all sort of different situations.

So what can I use bloginfo for?

All sorts of different things. Here’s the complete list, courtesy of the codex. It doesn’t make too much sense on it’s own if you don’t already know what you’re doing, so I’ve added in a little explanation below each.

  1. admin_email = admin@example

Email of the administrator.

  1. atom_url = http://example/home/feed/atom

Atom feed URL

  1. charset = UTF-8

The character ecoding system (not particularily interesting – used in the ).

  1. comments_atom_url = http://example/home/comments/feed/atom

Atom feed for all comments on the blog.

  1. comments_rss2_url = http://example/home/comments/feed

RSS feed for all comments on the blog.

  1. description = Just another WordPress blog

The description (or tagline) of your blog, as set under ‘Settings’ in the backend.

  1. url = http://example/home

Homepage of the blog.

  1. html_type = text/html

Type of HTML used (again, not too interesting :P ).

  1. language = en-GB

Language used on the blog.

  1. name = Testpilot

Name or title of your blog, as set under ‘Settings’ in the backend.

  1. pingback_url = http://example/home/wp/xmlrpc.php

URL to which pingbacks should be sent.

  1. rdf_url = http://example/home/feed/rdf

a general method for conceptual description or modeling of information that is implemented in web resources; using a variety of syntax formats.

via Wikipedia

  1. rss2_url = http://example/home/feed

RSS feed for the blog.

  1. rss_url = http://example/home/feed/rss

URL of the RSS feed.

  1. siteurl = http://example/home

URL of the site.

  1. stylesheet_directory = http://example/home/wp/wp-content/themes/largo

Directory where the style.css file is located, should be used for child theme.

  1. stylesheet_url = http://example/home/wp/wp-content/themes/largo/style.css

URL of the stylesheet.

  1. template_directory = http://example/home/wp/wp-content/themes/largo

Directory of your theme.

  1. template_url = http://example/home/wp/wp-content/themes/largo

URL of the theme.

  1. text_direction = ltr

Direction in which the text reads (ie left to right).

  1. version = 2.8.5

Version of WordPress the blog is running.

  1. wpurl = http://example/home/wp

URL of the WordPress installation (sometimes different to where the homepage is).

When should bloginfo be used?

Good question. It should be used for ‘stuff’ that is unique to your installation of WordPress (for example the title or homepage). Let’s say we want to send a link to the homepage. On your installation it’s at /word/, but on mine it’s at /press/! You want to share the theme you’re using with me, so obviously I’m going to have to change all the links to the homepage, right? Not true. Using the siteurl parameter, the homepage URL can be dynamically generated. So instead of links reading:

  1. <a href="/word/">Homepage</a>

They should be:

  1. <a href="<?php bloginfo('siteurl'); ?>Homepage</a></code>

That format applies to all uses of bloginfo :

  1. <?php bloginfo('parameter_here'); ?></code>

Further examples

Stylesheet URL. On my installation it’s /press/wp-content/themes/Biblioteca/style.css but on yours it’s /word/wordpress-installed-in-a-different-directory-to-the-homepage/wp-content/themes/Biblioteca/style.css. Bloginfo to the rescue again – instead of:

  1. <link rel="stylesheet" href="/press/wp-content/themes/Biblioteca/style.css" type="text/css" media="screen,projection" />

You can dynamically generate the stylesheet URL:

  1. <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen,projection" />

The final example I’ll do today is the title. On my blog it’s Press! but on yours it’s Word! Using the name parameter we can dynamically generate the title:

  1. <h2><?php bloginfo('name'); ?></h2>

And with that, we’re done. Enjoy your new-found knowledge!

No related posts.

Tags: ,

Follow on Twitter! Subscribe!
Alex's Gravatar

Alex Denning is the founder of WPShout. A WordPress developer from London, Alex co-founded WPShift at the start of 2010 where he sells awesome WordPress themes.

You can find Alex on Twitter and at AlexDenning.com.

3 Responses to “WordPress’ Bloginfo Explained”

  1. Epic Alex

    24. Oct, 2009

    Really useful list and explanations Alex.

    One thing I would add though is that if you aren’t designing a theme to be used by other people, where these things are constants as opposed to variables, it’s better to hard code them.
    .-= Epic Alex´s last blog ..5 Sites That Will Pay You For Your Coding Knowledge =-.

    Reply to this comment
    • Alex Denning

      27. Oct, 2009

      Tis true although if you’re using some sort of caching plugin then that isn’t a problem. Even if you’re not it’s a negligible effect on load times.

      Reply to this comment
  2. Thomas Scholz

    06. Dec, 2009

    ‘stylesheet_directory’ and ‘template_directory’ point to different places if you use a child theme. ‘template_directory’ gives you the path to the parent theme, ‘stylesheet_directory’ to the child. Lousy names, in my opinion.

    ‘charset’ is useful for forms: You should use it for the accept-charset attribute to avoid mixed encodings.

    Reply to this comment

Leave a Reply

Please use your real name when commenting. Wrap code in <code> tags and make sure HTML is encoded. You can use regular HTML like <a href="... etc.

Get yours questions answered quicker

If you're using this post for paid work and have a question of any complexity then please ask at WPQuestions where you'll get a prompt response.