wppaste
WordPress

twentytwenty_body_classes( array $classes ): array

Since
Twenty Twenty 1.0
Source
wp-content/themes/twentytwenty/inc/template-tags.php:686
Adds conditional body classes.

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

Reaches the database via get_post().

Scaling
Constant

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

Instructions
101–136

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()one call below twentytwenty_body_classes()
  • querycontent queryget_post()one call below twentytwenty_body_classes()
  • cacheobject cachewp_cache_get()one call below twentytwenty_body_classes()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
!isset($post) && !is_singular() && !is_page_template() && !is_single()101–111is_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–113is_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–117is_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–116is_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–119is_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–119is_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–117is_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–119is_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–121is_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–122is_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–121is_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–122is_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–121is_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–125is_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–124is_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–125is_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–124is_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–125is_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–127is_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–125is_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–127is_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–128is_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–129is_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–130is_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–130is_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–129is_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–133is_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–132is_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–133is_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–136is_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

PHPCompiledExecutedBranchesNotes
8.6-dev161101–13624
8.5161101–13624
8.4161101–13624
8.3161101–13624
8.2161101–13624
8.1161101–136241 fewer instruction than PHP 7.4
7.4162101–13624

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

Show all 15

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.

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