A variety of information about a blog can be entered in the WordPress administration panel. Displaying that information publicly is the responsibility of the active theme. One piece of information that you may want to display is the name of the blog.
First, you must locate the position at which the blog name should be displayed in your theme. Open the appropriate theme file (header.php is a good place to start) and place your cursor at the desired location. For the purposes of this recipe, you'll be inserting the blog's name as the value of the title
tag.
Locate the title
tag and remove whatever value is contained within it. Now, insert the bloginfo
function and make the markup look like the following:
<title><?php bloginfo('name'); ?></title>
When the blog name is set in the administrative panel, the value that the user enters is stored in the options table within the WordPress database. When you call bloginfo
with name
as the argument, the name of the blog is retrieved from the options table and displayed.
Note
Benefits of open source
WordPress is open source software. As such, you can examine the code base directly when you want to see how things are implemented. To get the most out of WordPress, you should look up functions that you use frequently, and bloginfo
is a great place to start. It gives you a good idea of the way WordPress stores and retrieves miscellaneous information, and can be found in wp-includes/general-template.php
.
Template tags, of which bloginfo
is one, often take one or more parameters that modify the output produced. With bloginfo
, the single parameter you can pass determines which piece of information about the blog should be displayed.
The sole parameter accepted by the bloginfo
function is a simple string. The following strings are supported, and must be passed in place of name
in the above code sample:
String |
Data Displayed |
---|---|
|
The blog's title |
|
The blog's tag line |
|
The URL to the blog's home page |
|
The URL to the WordPress installation |
|
The URL for the blog's RDF/RSS 1.0 feed |
|
The URL for the blog's RSS 0.92 feed |
|
The URL for the blog's ATOM feed |
|
The URL for the blog's comments RSS 2.0 feed |
|
The URL for the pingback XML-RPC file |
|
The URL for the primary CSS file of the active theme |
|
The URL of the style sheet directory of the active theme |
|
The URL of the active theme's directory |
|
The e-mail address of the blog administrator |
|
The blog's encoding for pages and feeds |
|
The blog's version of WordPress |
|
The content type of WordPress HTML pages |
To retrieve a piece of information for storage in a variable or for further manipulation, use the get_bloginfo
function instead of bloginfo. get_bloginfo
returns information instead of printing it, and supports the same parameters as bloginfo
.
As an example, perhaps you want to capitalize the blog name for some reason. The following would allow you to do so:
<?php echo strtoupper(get_bloginfo('name')); ?>