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
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
- Scaling
- Constant
- Instructions
- 39–106
- Plugin surface
- 2 hooks
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 121.
Third-party callbacks on 'twentytwenty_site_logo_args', 'twentytwenty_site_logo' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below twentytwenty_site_logo() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
is_front_page() && !has_custom_logo() | 39 | get_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() | 39 | get_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() | 42 | get_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–72 | get_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–72 | get_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–75 | get_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–92 | get_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–85 | get_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–92 | get_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–85 | get_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–95 | get_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–88 | get_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–93 | get_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–93 | get_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–103 | get_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–103 | get_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–96 | get_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–106 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 121 | 39–106 | 11 | |
| 8.5 | 121 | 39–106 | 11 | |
| 8.4 | 121 | 39–106 | 11 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 124 | 39–109 | 11 | |
| 8.2 | 124 | 39–109 | 11 | |
| 8.1 | 124 | 39–109 | 11 | |
| 7.4 | 124 | 39–109 | 11 |
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:
- apply_filters( twentytwenty_site_logo_args )filterline 60 (+26 into the body)
Filters the arguments for `twentytwenty_site_logo()`.
- 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
- get_queried_object_id()Retrieves the ID of the currently queried object.
- is_paged()Determines whether the query is for a paged result and not for the first page.
Used by · 1
- twentytwenty_customize_partial_site_logo()Renders the site logo for the selective refresh partial.
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.
Signature, return type and hooks compared across 5 parsed releases.
string to string|void.verified against sourceAbout 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.