Using WordPress ‘bloginfo()’ PHP function

The bloginfo() WordPress PHP function displays various pieces of information about the current site. It’s a handy tool for retrieving key site details, such as the site name, URL, and description.

Usage

Here’s a simple usage of the function:

bloginfo('name');  // Outputs the site name

Parameters

  • $show (string, optional) – Specifies the site information to display. Default is an empty string.

More information

See WordPress Developer Resources: bloginfo()

The function echoes the result immediately, so if you need to use any of the bloginfo() parameters as variables, you should use get_bloginfo() instead. This function returns the result as a string.

Examples

Display the Blog Title

To display the title of your blog, you can use the following code:

<h1>bloginfo('name');</h1> // Displays your blog's title in a h1 tag.

Display the Blog Description

Here’s how to display the tagline of your blog as set in Settings > General:

<p>bloginfo('description');</p> // Displays the tagline of your blog in a p tag.

This example displays the blog’s title in a link:

<a href="bloginfo('url');" title="bloginfo('name');">bloginfo('name');</a>

Hide Description if Empty

This practical example could be used as it is in themes. It hides the description if it’s empty:

if (get_bloginfo('description') !== '') {
    echo '<a class="site-description">bloginfo('description');</a>';
}

Show the Character Set

To display the character set your blog is using (e.g., “utf-8”):

<p>Character set: bloginfo('charset');</p>