twentytwenty_body_classes( array $classes ): array
- Since
- Twenty Twenty 1.0
- Source
wp-content/themes/twentytwenty/inc/template-tags.php:686
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
$classesarray- Classes added to the body tag.
Return value
array- Classes added to the body tag.
Performance profile
How much work a call to twentytwenty_body_classes() 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
- Heavy
- Scaling
- Constant
- Instructions
- 101–136
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
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 161.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below twentytwenty_body_classes() - querycontent query
get_post()one call below twentytwenty_body_classes() - cacheobject cache
wp_cache_get()one call below twentytwenty_body_classes() - serializeserialisation
maybe_unserialize()one call below twentytwenty_body_classes()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 30 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost twentytwenty_body_classes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($post) && !is_singular() && !is_page_template() && !is_single() | 101–111 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && get_next_post() | 105–113 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && !is_single() && $post_type === "post" | 106–117 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && !get_next_post() | 107–116 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_single() | 109–119 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && !is_single() && $post_type !== "post" && comments_open() | 109–119 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), comments_open(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && !is_single() && $post_type !== "post" && !comments_open() && !get_comments_number() | 109–117 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), comments_open(), get_comments_number(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && get_next_post() && $post_type === "post" | 110–119 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && !is_single() && $post_type !== "post" && !comments_open() && get_comments_number() | 112–121 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), comments_open(), get_comments_number(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && !get_next_post() && $post_type === "post" | 112–122 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && get_next_post() | 113–121 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && get_next_post() && $post_type !== "post" && comments_open() | 113–122 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), comments_open(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
18 further outcomes, up to 136 instructions
!isset($post) && !is_singular() && !is_page_template() && is_single() && get_next_post() && $post_type !== "post" && !comments_open() && !get_comments_number() | 113–121 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), comments_open(), get_comments_number(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_single() && $post_type === "post" | 114–125 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && !get_next_post() | 115–124 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && !get_next_post() && $post_type !== "post" && comments_open() | 115–125 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), comments_open(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && !get_next_post() && $post_type !== "post" && !comments_open() && !get_comments_number() | 115–124 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), comments_open(), get_comments_number(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && get_next_post() && $post_type !== "post" && !comments_open() && get_comments_number() | 116–125 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), comments_open(), get_comments_number(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_single() && $post_type !== "post" && comments_open() | 117–127 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), comments_open(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_single() && $post_type !== "post" && !comments_open() && !get_comments_number() | 117–125 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), comments_open(), get_comments_number(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && get_next_post() && $post_type === "post" | 118–127 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_page_template() && is_single() && !get_next_post() && $post_type !== "post" && !comments_open() && get_comments_number() | 118–128 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), comments_open(), get_comments_number(), post_password_required(), get_option(), is_page_template(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && !is_single() && $post_type !== "post" && !comments_open() && get_comments_number() | 120–129 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), comments_open(), get_comments_number(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && !get_next_post() && $post_type === "post" | 120–130 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && get_next_post() && $post_type !== "post" && comments_open() | 121–130 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), comments_open(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && get_next_post() && $post_type !== "post" && !comments_open() && !get_comments_number() | 121–129 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), comments_open(), get_comments_number(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && !get_next_post() && $post_type !== "post" && comments_open() | 123–133 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), comments_open(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && !get_next_post() && $post_type !== "post" && !comments_open() && !get_comments_number() | 123–132 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), comments_open(), get_comments_number(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && get_next_post() && $post_type !== "post" && !comments_open() && get_comments_number() | 124–133 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), comments_open(), get_comments_number(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
!isset($post) && !is_singular() && is_single() && !get_next_post() && $post_type !== "post" && !comments_open() && get_comments_number() | 126–136 | is_singular(), is_page_template(), is_page_template(), get_theme_mod(), is_singular(), is_singular(), is_customize_preview(), is_single(), get_next_post(), get_previous_post(), comments_open(), get_comments_number(), post_password_required(), get_option(), is_page_template(), get_page_template_slug(), basename(), has_nav_menu(), has_nav_menu(), is_active_sidebar(), is_active_sidebar(), get_theme_mod(), ltrim(), strtolower(), get_theme_mod(), ltrim(), strtolower() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 161 | 101–136 | 24 | |
| 8.5 | 161 | 101–136 | 24 | |
| 8.4 | 161 | 101–136 | 24 | |
| 8.3 | 161 | 101–136 | 24 | |
| 8.2 | 161 | 101–136 | 24 | |
| 8.1 | 161 | 101–136 | 24 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 162 | 101–136 | 24 |
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.
Uses · 15
- is_singular()Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).
- is_page_template()Determines whether the current post uses a page template.
- get_theme_mod()Retrieves theme modification value for the active theme.
- has_post_thumbnail()Determines whether a post has an image attached.
- is_customize_preview()Whether the site is being previewed in the Customizer.
- is_single()Determines whether the query is for an existing single post.
- get_next_post()Retrieves the next post that is adjacent to the current post.
- get_previous_post()Retrieves the previous post that is adjacent to the current post.
- comments_open()Determines whether the current post is open for comments.
- get_comments_number()Retrieves the amount of comments a post has.
- post_password_required()Determines whether the post requires password and whether a correct password has been provided.
- get_option()Retrieves an option value based on an option name.
Show all 15
- get_page_template_slug()Gets the specific template filename for a given post.
- has_nav_menu()Determines whether a registered nav menu location has a menu assigned to it.
- is_active_sidebar()Determines whether a sidebar contains widgets.
Source code
function twentytwenty_body_classes( $classes ) { global $post; $post_type = isset( $post ) ? $post->post_type : false; // Check whether we're singular. if ( is_singular() ) { $classes[] = 'singular'; } // Check whether the current page should have an overlay header. if ( is_page_template( array( 'templates/template-cover.php' ) ) ) { $classes[] = 'overlay-header'; } // Check whether the current page has full-width content. if ( is_page_template( array( 'templates/template-full-width.php' ) ) ) { $classes[] = 'has-full-width-content'; } // Check for enabled search. if ( true === get_theme_mod( 'enable_header_search', true ) ) { $classes[] = 'enable-search-modal'; } // Check for post thumbnail. if ( is_singular() && has_post_thumbnail() ) { $classes[] = 'has-post-thumbnail'; } elseif ( is_singular() ) { $classes[] = 'missing-post-thumbnail'; } // Check whether we're in the customizer preview. if ( is_customize_preview() ) { $classes[] = 'customizer-preview'; } // Check if posts have single pagination. if ( is_single() && ( get_next_post() || get_previous_post() ) ) { $classes[] = 'has-single-pagination'; } else { $classes[] = 'has-no-pagination'; } // Check if we're showing comments. if ( $post && ( ( 'post' === $post_type || comments_open() || get_comments_number() ) && ! post_password_required() ) ) { $classes[] = 'showing-comments'; } else { $classes[] = 'not-showing-comments'; } // Check if avatars are visible. $classes[] = get_option( 'show_avatars' ) ? 'show-avatars' : 'hide-avatars'; // Slim page template class names (class = name - file suffix). if ( is_page_template() ) { $classes[] = basename( get_page_template_slug(), '.php' ); } // Check for the elements output in the top part of the footer. $has_footer_menu = has_nav_menu( 'footer' ); $has_social_menu = has_nav_menu( 'social' ); $has_sidebar_1 = is_active_sidebar( 'sidebar-1' ); $has_sidebar_2 = is_active_sidebar( 'sidebar-2' ); // Add a class indicating whether those elements are output. if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) { $classes[] = 'footer-top-visible'; } else { $classes[] = 'footer-top-hidden'; } // Get header/footer background color. $header_footer_background = get_theme_mod( 'header_footer_background_color', '#ffffff' ); $header_footer_background = strtolower( '#' . ltrim( $header_footer_background, '#' ) ); // Get content background color. $background_color = get_theme_mod( 'background_color', 'f5efe0' ); $background_color = strtolower( '#' . ltrim( $background_color, '#' ) );Changelog
Introduced in Twenty Twenty 1.0. Unchanged from 6.7.7 through 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-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.