bloginfo()
Displays information about the current site.
Displays information about your site, mostly gathered from the information you supply in your User Profile and General Settings WordPress Administration Screens. It can be used anywhere within a template file. This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().
For newbies
For those who do not know yet, I want to dispel the myth that getting data through this function leads to excessive load on the hosting. In fact, nothing of the sort! Once I thought so too, but after a series of tests I made sure that the load would be barely noticeable if through this function you get about 5 thousand data. Therefore, do not believe if someone says that bloginfo()
or get_bloginfo()
overload the server!
If you do not specify the $show parameter, the blog name will be displayed. If you specify not known values, the name of the blog will be displayed too.
No Hooks.
Return
null
. Nothing (null).
Usage
bloginfo( $show );
- $show(string)
Site information to display. Possible values:
name
- Site title.description
- Site description.template_url
- URL of the active theme’s directory.stylesheet_url
- Primary CSS (usually style.css) file URL of the active theme.rss2_url
- RSS 2.0 feed URL (/feed).comments_rss2_url
- Comments RSS 2.0 feed URL (/comments/feed).pingback_url
- Pingback XML-RPC file URL (xmlrpc.php).charset
- Charset encoding of the website. Note: This parameter always echoes UTF-8, which is the default encoding of WordPress.version
- WordPress Version you use.html_type
- Content-Type of WordPress HTML pages (default: “text/html”).language
- Language of WordPress, for example, en-US.
Rarely used:
stylesheet_directory
- Stylesheet directory URL of the active theme. Better use get_stylesheet_directory_uri() instead.template_directory
- Stylesheet directory URL of the active theme. Better use get_template_directory() instead.admin_email
- “E-mail address” set in Settings > General.rdf_url
- RDF/RSS 1.0 feed URL (/feed/rfd).rss_url
- RSS 0.92 feed URL (/feed/rss).atom_url
- Atom feed URL (/feed/atom).url
- URL of the website (WordPress address (URL) in Settings > General). Same as home_url().wpurl
- WordPress URL (WordPress address (URL) in Settings > General). Same as site_url().
Deprecated:
home
- Deprecated since version 2.2. Use home_url() instead.siteurl
- Deprecated since version 2.2. Use site_url() instead.
Default: ''
Examples
#1 Display the site name in <h1> tag:
<h1><?php bloginfo('name'); ?></h1>
#2 Display the encoding of the site:
<p>Charset: <?php bloginfo('charset'); ?></p>
#3 Display the description of the site:
<p><?php bloginfo('description'); ?> </p>
#4 bloginfo() vs get_bloginfo()
If using bloginfo() as a variable, for example: $url = bloginfo('url');
it will return null
.
This is because bloginfo() echos the result immediately. So if you want to use any of the bloginfo() as variables use get_bloginfo(). This function returns the result as a string.
#5 Example output
In this example case, the Site Address (URL) is shown as http://www.example.com/home
, and the WordPress address (URL) is displayed as http://www.example.com/home/wp
.
Please note that directory URLs are missing trailing slashes.
admin_email = [email protected] atom_url = http://www.example.com/home/feed/atom charset = UTF-8 comments_atom_url = http://www.example.com/home/comments/feed/atom comments_rss2_url = http://www.example.com/home/comments/feed description = Just another WordPress blog home = http://www.example.com/home (DEPRECATED! use url option instead) html_type = text/html language = en-US name = Testpilot pingback_url = http://www.example.com/home/wp/xmlrpc.php rdf_url = http://www.example.com/home/feed/rdf rss2_url = http://www.example.com/home/feed rss_url = http://www.example.com/home/feed/rss siteurl = http://www.example.com/home (DEPRECATED! use url option instead) stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/largo stylesheet_url = http://www.example.com/home/wp/wp-content/themes/largo/style.css template_directory = http://www.example.com/home/wp/wp-content/themes/largo template_url = http://www.example.com/home/wp/wp-content/themes/largo text_direction = ltr url = http://www.example.com/home version = 3.5 wpurl = http://www.example.com/home/wp
#6 Hides description if empty
Practical example that could be used in themes.
<?php if ( $desc = get_bloginfo( 'description' ) ) { ?> <a class="site-description"><?= $desc ?></a> <?php } ?>
Notes
- See: get_bloginfo() For possible $show values
Changelog
Since 0.71 | Introduced. |
bloginfo() bloginfo code WP 6.7.1
function bloginfo( $show = '' ) { echo get_bloginfo( $show, 'display' ); }