add_theme_support() – Registers theme support for a given feature.

You appear to be a bot. Output may be restricted

Description

Registers theme support for a given feature.

Must be called in the theme's functions.php file to work. If attached to a hook, it must be after_setup_theme . The initinit hook may be too late for some features. Example usage:

  • add_theme_support( 'title-tag' );
  • add_theme_support( 'custom-logo', array(
  • 'height' => 480,
  • 'width' => 720,
  • ) );

Usage

$void|false = add_theme_support( $feature, $args );

Parameters

$feature
( string ) required – The feature being added. Likely core values include:

  • 'admin-bar'
  • 'align-wide'
  • 'automatic-feed-links'
  • 'core-block-patterns'
  • 'custom-background'
  • 'custom-header'
  • 'custom-line-height'
  • 'custom-logo'
  • 'customize-selective-refresh-widgets'
  • 'custom-spacing'
  • 'custom-units'
  • 'dark-editor-style'
  • 'disable-custom-colors'
  • 'disable-custom-font-sizes'
  • 'editor-color-palette'
  • 'editor-gradient-presets'
  • 'editor-font-sizes'
  • 'editor-styles'
  • 'featured-content'
  • 'html5'
  • 'menus'
  • 'post-formats'
  • 'post-thumbnails'
  • 'responsive-embeds'
  • 'starter-content'
  • 'title-tag'
  • 'wp-block-styles'
  • 'widgets'
  • 'widgets-block-editor'
$args
( mixed ) optional

Returns

void|false Void on success, false on failure.

Source

File name: wordpress/wp-includes/theme.php
Lines:

1 to 100 of 245
function add_theme_support( $feature, ...$args ) {
  global $_wp_theme_features;

  if ( ! $args ) {
    $args = true;
  }

  switch ( $feature ) {
    case 'post-thumbnails':
      // All post types are already supported.
      if ( true === get_theme_support( 'post-thumbnails' ) ) {
        return;
      }

      /*
			 * Merge post types with any that already declared their support
			 * for post thumbnails.
			 */
      if ( isset( $args[0] ) && is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) {
        $args[0] = array_unique( array_merge( $_wp_theme_features['post-thumbnails'][0], $args[0] ) );
      }

      break;

    case 'post-formats':
      if ( isset( $args[0] ) && is_array( $args[0] ) ) {
        $post_formats = get_post_format_slugs();
        unset( $post_formats['standard'] );

        $args[0] = array_intersect( $args[0], array_keys( $post_formats ) );
      } else {
        _doing_it_wrong(
          "add_theme_support( 'post-formats' )",
          __( 'You need to pass an array of post formats.' ),
          '5.6.0'
        );
        return false;
      }
      break;

    case 'html5':
      // You can't just pass 'html5', you need to pass an array of types.
      if ( empty( $args[0] ) || ! is_array( $args[0] ) ) {
        _doing_it_wrong(
          "add_theme_support( 'html5' )",
          __( 'You need to pass an array of types.' ),
          '3.6.1'
        );

        if ( ! empty( $args[0] ) && ! is_array( $args[0] ) ) {
          return false;
        }

        // Build an array of types for back-compat.
        $args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
      }

      // Calling 'html5' again merges, rather than overwrites.
      if ( isset( $_wp_theme_features['html5'] ) ) {
        $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] );
      }
      break;

    case 'custom-logo':
      if ( true === $args ) {
        $args = array( 0 => array() );
      }
      $defaults = array(
        'width'                => null,
        'height'               => null,
        'flex-width'           => false,
        'flex-height'          => false,
        'header-text'          => '',
        'unlink-homepage-logo' => false,
      );
      $args[0]  = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults );

      // Allow full flexibility if no size is specified.
      if ( is_null( $args[0]['width'] ) && is_null( $args[0]['height'] ) ) {
        $args[0]['flex-width']  = true;
        $args[0]['flex-height'] = true;
      }
      break;

    case 'custom-header-uploads':
      return add_theme_support( 'custom-header', array( 'uploads' => true ) );

    case 'custom-header':
      if ( true === $args ) {
        $args = array( 0 => array() );
      }

      $defaults = array(
        'default-image'          => '',
        'random-default'         => false,
        'width'                  => 0,
        'height'                 => 0,
        'flex-height'            => false,
        'flex-width'             => false,
        'default-text-color'     => '',
 

 View on GitHub View on Trac