• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / twentytwenty_body_classes() – Add conditional body classes.

You appear to be a bot. Output may be restricted

Description

Adds conditional body classes.

Usage

$array = twentytwenty_body_classes( $classes );

Parameters

$classes
( array ) required – Classes added to the body tag.

Returns

array Classes added to the body tag.

Source

File name: twentytwenty/inc/template-tags.php
Lines:

1 to 88 of 88
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, '#' ) );

  // Add extra class if main background and header/footer background are the same color.
  if ( $background_color === $header_footer_background ) {
    $classes[] = 'reduced-spacing';
  }

  return $classes;

}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: twentytwenty_body_classes
Plugin ref: Twenty Twenty
Version: 2.1
Sourcefile: inc/template-tags.php
File ref: inc/template-tags.php
Deprecated?: No
API Letters: B,C,T

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites