How to retrieve site information in WordPress using get_bloginfo

The WordPress get_bloginfo function retrieves information about the current site or blog, such as the site title, description, URL, and more. This function can be useful for displaying dynamic information about the site in various areas, such as the header, footer, or sidebar of a WordPress theme.

By using get_bloginfo, developers can easily access and display important site information without hardcoding it into their theme files. This allows for greater flexibility and easier maintenance of the site’s content and settings.

Parameters accepted by the WordPress get_bloginfo function

The get_bloginfo function accepts the following parameters:

  • $show (string, optional): Site info to retrieve. Default empty (site name).
  • $filter (string, optional): How to filter what is retrieved. Default ‘raw’.

Value returned by the WordPress get_bloginfo function

The get_bloginfo function returns a string, mostly string values, which might be empty.

Examples

How to get the site name using get_bloginfo

<p>
<?php
 $site_name = get_bloginfo('name');
 echo $site_name;
?>
</p>

This code snippet retrieves the name of the current site using the get_bloginfo function and stores it in the $site_name variable. It then prints the site name using echo.

How to get the site description using get_bloginfo

<p>
<?php
 $site_description = get_bloginfo('description');
 echo $site_description;
?>
</p>

This code snippet retrieves the description of the current site using the get_bloginfo function and stores it in the $site_description variable. It then prints the site description using echo.

How to get the site URL using get_bloginfo

<p>
<?php
 $site_url = get_bloginfo('url');
 echo $site_url;
?>
</p>

This code snippet retrieves the URL of the current site using the get_bloginfo function and stores it in the $site_url variable. It then prints the site URL using echo.

Conclusion

The get_bloginfo function is an essential tool for retrieving various information about a WordPress site. Whether it’s the site’s name, description, URL, or any other piece of information stored in the site’s database, this function provides a simple and efficient way to access it. By understanding how to use this function and its various parameters, developers can enhance their ability to customize and manipulate WordPress sites to better suit their needs.

With its versatility and ease of use, get_bloginfo is a valuable asset for WordPress developers and site administrators alike. By incorporating this function into their workflow, they can streamline the process of accessing and displaying important site information, ultimately improving the overall functionality and user experience of their WordPress sites.

Related WordPress Functions