get_bloginfo()
Retrieves information about the current site.
Possible values for $show include:
- 'name' - Site title (set in Settings > General)
- 'description' - Site tagline (set in Settings > General)
- 'wpurl' - The WordPress address (URL) (set in Settings > General)
- 'url' - The Site address (URL) (set in Settings > General)
- 'admin_email' - Admin email (set in Settings > General)
- 'charset' - The "Encoding for pages and feeds" (set in Settings > Reading)
- 'version' - The current WordPress version
- 'html_type' - The Content-Type (default: "text/html"). Themes and plugins can override the default value using the {@see 'pre_option_html_type'} filter
- 'text_direction' - The text direction determined by the site's language. is_rtl() should be used instead
- 'language' - Language code for the current site
- 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme will take precedence over this value
- stylesheet_directory Directory path for the active theme. An active child theme will take precedence over this value
- 'template_url' / template_directory URL of the active theme's directory. An active child theme will NOT take precedence over this value
- 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php)
- 'atom_url' - The Atom feed URL (/feed/atom)
- 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rdf)
- 'rss_url' - The RSS 0.92 feed URL (/feed/rss)
- 'rss2_url' - The RSS 2.0 feed URL (/feed)
- 'comments_atom_url' - The comments Atom feed URL (/comments/feed)
- 'comments_rss2_url' - The comments RSS 2.0 feed URL (/comments/feed)
Some $show values are deprecated and will be removed in future versions. These options will trigger the _deprecated_argument() function.
Deprecated arguments include:
- 'siteurl' - Use 'url' instead
- 'home' - Use 'url' instead
Hooks from the function
Return
String
. Mostly string values, might be empty.
Usage
get_bloginfo( $show, $filter );
- $show(string)
- Site info to retrieve.
Default: empty (site name) - $filter(string)
- How to filter what is retrieved.
Default: 'raw'
Examples
#1 Demo examples
Let's pass the name of the blog to the variable $blog_title to use the variable somewhere afterwards.
<?php $blog_title = get_bloginfo(); ?> //use a variable <?php echo $blog_title ?>
The same will be returned by the function if you write it this way:
<?php $blog_title = get_bloginfo('name'); ?>
A possible example of the use of the function in a WordPress template:
<?php echo 'Blog short description: ' . get_bloginfo( 'description', 'display' ); ?> // as a result the following inscription will appear on the screen: // A short description of the blog: <here description>
#2 Fetch all info about a website
There should be a possibility to return the array of all available info. Although this might not be a good practice in terms of performance this should help someone who needs to fetch all info about a website.
function bloginfo_array() { $fields = array( 'name', 'description', 'wpurl', 'url', 'admin_email', 'charset', 'version', 'html_type', 'text_direction', 'language' ); $data = array(); foreach( $fields as $field ) { $data[ $field ] = get_bloginfo( $field ); } return $data; }
Note that I’ve omitted some fields that might not be that important.
#3 Fields that can be specified in $show
The names that can be passed to the function in the $show parameter and what it will eventually output:
Option | Description |
---|---|
name | Site name: Settings > Basic |
description | Site Description: Settings > Basic |
wpurl | URL site (admin panel): Settings > Basic . The data is taken from the "siteurl" option wp_options. Alias site_url(). |
url | URL site (front): Settings > Basic . The data is taken from the "home" option wp_options. Alias home_url() |
admin_email | Admin Email: Settings > Basic . The data is taken from "admin_email" in table wp_options. |
charset | Blog charset. The data are taken from "blog_charset" in table wp_options. Since version 3.5 the blog encoding is not configurable from the admin panel and this parameter is always utf-8. |
version | WP version. The data is taken from the variable $wp_version. |
html_type | The content type of the HTML page (default: "text/html"). The data is taken from "html_type" in the table wp_options. Themes and plugins can rewrite this variable through the hook pre_option_html_type . |
language | Site language (locale), for example ru-RU. |
stylesheet_url | URL to CSS stylesheet (usually style.css). Alias get_stylesheet_uri(). |
stylesheet_directory | URL to the themes directory where the stylesheet file is located. Alias get_stylesheet_directory_uri(). |
template_directory template_url |
URL to the themes directory. Alias get_template_directory_uri(). |
pingback_url | URL of the XML-RPC pings file (xmlrpc.php). |
atom_url | Atom feed URL (/feed/atom). |
rdf_url | RDF/RSS 1.0 feed URL (/feed/rfd). |
rss_url | RSS 0.92 feed URL (/feed/rss). |
rss2_url | RSS 2.0 feed URL (/feed). |
comments_atom_url | Atom feed comment URL (/comments/feed). |
comments_rss2_url | URL of RSS 2.0 comment feed (/comments/feed). |
home | Prohibited since version 2.2. Use home_url(). |
siteurl | Prohibited since version 2.2. Use site_url(). |
Same parameters with values:
admin_email = [email protected] atom_url = http://example.ru/feed/atom charset = UTF-8 comments_atom_url = http://example.ru/comments/feed/atom comments_rss2_url = http://example.ru/comments/feed description = Just another WordPress blog html_type = text/html language = en-US name = Testpilot pingback_url = http://example.ru/xmlrpc.php rdf_url = http://example.ru/feed/rdf rss2_url = http://example.ru/feed rss_url = http://example.ru/feed/rss stylesheet_directory = http://example.ru/wp-content/themes/largo stylesheet_url = http://example.ru/wp-content/themes/largo/style.css template_directory = http://example.ru/wp-content/themes/largo template_url = http://example.ru/wp-content/themes/largo text_direction = ltr url = http://example.ru version = 2.7 wpurl = http://example.ru
#4 Network Tagline
Using this example, you can obtain the name and description for the network home:
switch_to_blog(1); $site_title = get_bloginfo( 'name' ); $site_url = network_site_url( '/' ); $site_description = get_bloginfo( 'description' ); restore_current_blog(); echo 'The Network Home URL is: ' . $site_url; echo 'The Network Home Name is: ' . $site_title; echo 'The Network Home Tagline is: ' . $site_description;
results in this being displayed on your blog:
The Network Home URL is: http://example.com/ The Network Home Name is: Example The Network Home Tagline is: The example site
#5 Blog Tagline
Using this example:
<?php printf( esc_html__( 'Your Blog Tagline is: %s', 'textdomain' ), get_bloginfo ( 'description' ) ); ?>
Results in this being displayed on your blog:
Your Blog Tagline is: All things WordPress
Notes
- Global. String. $wp_version The WordPress version string.
Changelog
Since 0.71 | Introduced. |