wppaste
WordPress

twentytwenty_site_logo( array $args = array(), bool $display = true ): string|void

Since
Twenty Twenty 1.0
Source
wp-content/themes/twentytwenty/inc/template-tags.php:34
Displays the site logo, either text or image.

Compatibility

WordPress
since Twenty Twenty 1.0
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

$argsarrayoptional
Arguments for displaying the site logo either as an image or text.Default: array()
$displaybooloptional
Display or return the HTML.Default: true

Return value

string|void
Compiled HTML based on our arguments.

Performance profile

How much work a call to twentytwenty_site_logo() 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
39–106

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

Plugin surface
2 hooks

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

Called by
1

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

What it touches

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

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 · 18 distinct outcomes

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

WhenInstructionsCalls it makes
is_front_page() && !has_custom_logo()39get_custom_logo(), get_bloginfo(), is_front_page(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo()
!is_front_page() && !is_home() && !has_custom_logo()39get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), wp_parse_args(), apply_filters(), has_custom_logo()
!is_front_page() && is_home() && !has_custom_logo()42get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo()
is_front_page() && has_custom_logo()70–72get_custom_logo(), get_bloginfo(), is_front_page(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), esc_html(), sprintf(), sprintf(), apply_filters()
!is_front_page() && !is_home() && has_custom_logo()70–72get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), wp_parse_args(), apply_filters(), has_custom_logo(), esc_html(), sprintf(), sprintf(), apply_filters()
!is_front_page() && is_home() && has_custom_logo()73–75get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), esc_html(), sprintf(), sprintf(), apply_filters()
is_front_page() && !has_custom_logo()83–92get_custom_logo(), get_bloginfo(), is_front_page(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_paged(), sprintf(), apply_filters()
!has_custom_logo() && !is_home()83–85get_custom_logo(), get_bloginfo(), is_front_page(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), sprintf(), apply_filters()
!is_home() && !has_custom_logo()83–92get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_paged(), sprintf(), apply_filters()
!is_front_page() && !is_home() && !has_custom_logo()83–85get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), sprintf(), apply_filters()
is_home() && !has_custom_logo()86–95get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_paged(), sprintf(), apply_filters()
!is_front_page() && !has_custom_logo()86–88get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), sprintf(), apply_filters()
6 further outcomes, up to 106 instructions
!has_custom_logo() && is_home()91–93get_custom_logo(), get_bloginfo(), is_front_page(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), get_option(), get_queried_object_id(), sprintf(), apply_filters()
!is_front_page() && !has_custom_logo()91–93get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), get_option(), get_queried_object_id(), sprintf(), apply_filters()
!has_custom_logo() && is_home()94–103get_custom_logo(), get_bloginfo(), is_front_page(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), get_option(), get_queried_object_id(), is_paged(), sprintf(), apply_filters()
!is_front_page() && !has_custom_logo()94–103get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), get_option(), get_queried_object_id(), is_paged(), sprintf(), apply_filters()
!is_front_page() && is_home() && !has_custom_logo()94–96get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), get_option(), get_queried_object_id(), sprintf(), apply_filters()
!is_front_page() && is_home() && !has_custom_logo()97–106get_custom_logo(), get_bloginfo(), is_front_page(), is_home(), is_page(), wp_parse_args(), apply_filters(), has_custom_logo(), get_home_url(), esc_url(), esc_html(), sprintf(), is_front_page(), is_home(), get_option(), get_queried_object_id(), is_paged(), sprintf(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12139–10611
8.512139–10611
8.412139–106113 fewer instructions than PHP 8.3
8.312439–10911
8.212439–10911
8.112439–10911
7.412439–10911

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 twentytwenty_site_logo() runs, in this order:

  1. apply_filters( twentytwenty_site_logo_args )filterline 60 (+26 into the body)

    Filters the arguments for `twentytwenty_site_logo()`.

  2. apply_filters( twentytwenty_site_logo )filterline 95 (+61 into the body)

    Filters the arguments for `twentytwenty_site_logo()`.

Uses · 14

  • get_custom_logo()Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
  • get_bloginfo()Retrieves information about the current site.
  • is_front_page()Determines whether the query is for the front page of the site.
  • is_home()Determines whether the query is for the blog homepage.
  • is_page()Determines whether the query is for an existing single page.
  • wp_parse_args()Merges user defined arguments into defaults array.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • has_custom_logo()Determines whether the site has a custom logo.
  • esc_html()Escaping for HTML blocks.
  • esc_url()Checks and cleans a URL.
  • get_home_url()Retrieves the URL for a given site where the front end is accessible.
  • get_option()Retrieves an option value based on an option name.
Show all 14

Used by · 1

Source code

function twentytwenty_site_logo( $args = array(), $display = true ) {	$logo       = get_custom_logo();	$site_title = get_bloginfo( 'name' );	$contents   = '';	$classname  = ''; 	$defaults = array(		'logo'        => '%1$s<span class="screen-reader-text">%2$s</span>',		'logo_class'  => 'site-logo',		'title'       => '<a href="%1$s" rel="home">%2$s</a>',		'title_class' => 'site-title',		'home_wrap'   => '<h1 class="%1$s">%2$s</h1>',		'single_wrap' => '<div class="%1$s faux-heading">%2$s</div>',		'condition'   => ( is_front_page() || is_home() ) && ! is_page(),	); 	$args = wp_parse_args( $args, $defaults ); 	/**	 * Filters the arguments for `twentytwenty_site_logo()`.	 *	 * @since Twenty Twenty 1.0	 *	 * @param array $args     Parsed arguments.	 * @param array $defaults Function's default arguments.	 */	$args = apply_filters( 'twentytwenty_site_logo_args', $args, $defaults ); 	if ( has_custom_logo() ) {		$contents  = sprintf( $args['logo'], $logo, esc_html( $site_title ) );		$classname = $args['logo_class'];	} else {		if ( ! $site_title ) {			return '';		} 		$contents = sprintf( $args['title'], esc_url( get_home_url( null, '/' ) ), esc_html( $site_title ) );		if (			( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) )			&& ! is_paged()			&& $args['title'] === $defaults['title']		) {			$contents = str_replace( ' rel=', ' aria-current="page" rel=', $contents );		}		$classname = $args['title_class'];	} 	$wrap = $args['condition'] ? 'home_wrap' : 'single_wrap'; 	$html = sprintf( $args[ $wrap ], $classname, $contents ); 	/**	 * Filters the arguments for `twentytwenty_site_logo()`.	 *	 * @since Twenty Twenty 1.0	 *	 * @param string $html      Compiled HTML based on our arguments.	 * @param array  $args      Parsed arguments.	 * @param string $classname Class name based on current view, home or single.	 * @param string $contents  HTML for site title or logo.	 */	$html = apply_filters( 'twentytwenty_site_logo', $html, $args, $classname, $contents ); 	if ( ! $display ) {		return $html;	} 	echo $html;}

Changelog

Introduced in Twenty Twenty 1.0. One change between 6.7.7 and 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.

7.0.4
Return type changed from string to string|void.verified against source
Twenty Twenty 1.0
Twenty Twenty 1.0from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentytwenty/inc/template-tags.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.