wppaste
WordPress

get_bloginfo( string $show = '', string $filter = 'raw' ): string

Since
0.71
Source
wp-includes/general-template.php:1018

Retrieve site info with get_bloginfo(): the site title, tagline, URL, WordPress version, language, charset, or feed URLs, selected by the $show argument. With no argument it returns the site name; pass 'display' as the second argument when echoing so the bloginfo filters run.

Retrieves information about the current site.

Description

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 '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

Compatibility

WordPress
since 0.71
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$showstringoptional
Site info to retrieve. Default empty (site name).Default: ''
$filterstringoptional
How to filter what is retrieved. Default 'raw'.Default: 'raw'

Return value

string
Mostly string values, might be empty.

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Print the site name and tagline in a header

Fetch the title and tagline with the 'display' filter when the values are going straight into markup.

$site_name = get_bloginfo( 'name', 'display' );
$tagline   = get_bloginfo( 'description', 'display' );

printf(
	'<a class="site-brand" href="%s">%s</a> <span class="tagline">%s</span>',
	esc_url( home_url( '/' ) ),
	esc_html( $site_name ),
	esc_html( $tagline )
);

'siteurl' and 'home' are deprecated $show values and trigger _deprecated_argument(); use 'url' for the site address and 'wpurl' for the WordPress install address, which differ when core lives in a subdirectory.

Performance profile

How much work a call to get_bloginfo() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–89

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 217.

Plugin surface
2 hooks

Third-party callbacks on 'bloginfo_url', 'bloginfo' run inside this call, and their cost is not bounded by anything here.

Called by
50

50 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below get_bloginfo()
  • serializeserialisationmaybe_unserialize()one call below get_bloginfo()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 26 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_bloginfo() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$filter !== "display"9–49none
$filter !== "display"10–16home_url()
$filter !== "display"10–35site_url()
$filter !== "display"10–56get_option()
$filter !== "display"10–36get_stylesheet_uri()
$filter !== "display"10–38get_stylesheet_directory_uri()
$filter !== "display"10–42get_template_directory_uri()
$filter !== "display"11–33get_feed_link()
$output !== "html_lang_attribute" && !$output && $filter !== "display"14–56__()
$filter === "display"17–61apply_filters()
$filter === "display"18–28home_url(), apply_filters()
$filter === "display"18–47site_url(), apply_filters()
14 further outcomes, up to 89 instructions
$filter === "display"18–68get_option(), apply_filters()
$filter === "display"18–48get_stylesheet_uri(), apply_filters()
$filter === "display"18–50get_stylesheet_directory_uri(), apply_filters()
$filter === "display"18–54get_template_directory_uri(), apply_filters()
$filter === "display"19–45get_feed_link(), apply_filters()
$filter !== "display"19–63__(), determine_locale()
$output !== "html_lang_attribute" && !$output && $filter === "display"22–68__(), apply_filters()
$filter !== "display"26–30__(), sprintf(), _deprecated_argument(), home_url()
$filter === "display"27–75__(), determine_locale(), apply_filters()
!function_exists() && $filter !== "display"28–72__(), sprintf(), _deprecated_argument(), function_exists()
function_exists() && $filter !== "display"32–77__(), sprintf(), _deprecated_argument(), function_exists(), is_rtl()
$filter === "display"34–42__(), sprintf(), _deprecated_argument(), home_url(), apply_filters()
!function_exists() && $filter === "display"36–84__(), sprintf(), _deprecated_argument(), function_exists(), apply_filters()
function_exists() && $filter === "display"40–89__(), sprintf(), _deprecated_argument(), function_exists(), is_rtl(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev2179–8932
8.52179–8932
8.42179–893215 fewer instructions than PHP 8.3
8.32329–9832
8.22329–9832
8.12329–9832
7.42329–9832

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while get_bloginfo() runs, in this order:

  1. apply_filters( bloginfo_url )filterline 1140 (+122 into the body)

    Filters the URL returned by get_bloginfo().

  2. apply_filters( bloginfo )filterline 1150 (+132 into the body)

    Filters the site information returned by get_bloginfo().

Uses · 13

Show all 13
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Used by · 50

Show all 50

Source code

function get_bloginfo( $show = '', $filter = 'raw' ) {	switch ( $show ) {		case 'home':    // Deprecated.		case 'siteurl': // Deprecated.			_deprecated_argument(				__FUNCTION__,				'2.2.0',				sprintf(					/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */					__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),					'<code>' . $show . '</code>',					'<code>bloginfo()</code>',					'<code>url</code>'				)			);			// Intentional fall-through to be handled by the 'url' case.		case 'url':			$output = home_url();			break;		case 'wpurl':			$output = site_url();			break;		case 'description':			$output = get_option( 'blogdescription' );			break;		case 'rdf_url':			$output = get_feed_link( 'rdf' );			break;		case 'rss_url':			$output = get_feed_link( 'rss' );			break;		case 'rss2_url':			$output = get_feed_link( 'rss2' );			break;		case 'atom_url':			$output = get_feed_link( 'atom' );			break;		case 'comments_atom_url':			$output = get_feed_link( 'comments_atom' );			break;		case 'comments_rss2_url':			$output = get_feed_link( 'comments_rss2' );			break;		case 'pingback_url':			$output = site_url( 'xmlrpc.php' );			break;		case 'stylesheet_url':			$output = get_stylesheet_uri();			break;		case 'stylesheet_directory':			$output = get_stylesheet_directory_uri();			break;		case 'template_directory':		case 'template_url':			$output = get_template_directory_uri();			break;		case 'admin_email':			$output = get_option( 'admin_email' );			break;		case 'charset':			$output = get_option( 'blog_charset' );			if ( '' === $output ) {				$output = 'UTF-8';			}			break;		case 'html_type':			$output = get_option( 'html_type' );			break;		case 'version':			global $wp_version;			$output = $wp_version;			break;		case 'language':			/*			 * translators: Translate this to the correct language tag for your locale,			 * see https://www.w3.org/International/articles/language-tags/ for reference.			 * Do not translate into your own language.			 */			$output = __( 'html_lang_attribute' );			if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {

Changelog

Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/general-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.