wppaste
WordPress

add_theme_support( string $feature, mixed $args ): void|false

Since
2.9.0, 3.4.0, 3.6.0, 3.6.1, 3.9.0, 4.1.0, 4.5.0, 4.7.0, 5.0.0, 5.3.0, 5.3.0, 5.4.0, 5.5.0, 5.5.0, 5.6.0, 5.8.0, 5.8.0, 6.0.0, 6.1.0, 6.1.0, 6.3.0, 6.3.0, 6.5.0, 6.6.0
Source
wp-includes/theme.php:2702
Registers theme support for a given feature.

Description

Must be called in the theme's functions.php file to work.
If attached to a hook, it must be 'after_setup_theme'.
The 'init' 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,
) );

Compatibility

WordPress
since 6.6.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

$featurestring
The feature being added. Likely core values include:
- 'admin-bar'
- 'align-wide'
- 'appearance-tools'
- 'automatic-feed-links'
- 'block-templates'
- 'block-template-parts'
- 'border'
- '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'
- 'disable-custom-gradients'
- 'disable-layout-styles'
- 'editor-color-palette'
- 'editor-gradient-presets'
- 'editor-font-sizes'
- 'editor-spacing-sizes'
- 'editor-styles'
- 'featured-content'
- 'html5'
- 'link-color'
- 'menus'
- 'post-formats'
- 'post-thumbnails'
- 'responsive-embeds'
- 'starter-content'
- 'title-tag'
- 'widgets'
- 'widgets-block-editor'
- 'wp-block-styles'
$argsmixed
Optional extra arguments to pass along with certain features.

Return value

void|false
Void on success, false on failure.

Performance profile

How much work a call to add_theme_support() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
10–102

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
32

32 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below add_theme_support()

Further down the call graph this can also reach query, option, cache, serialize 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 · 14 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost add_theme_support() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always10add_theme_support()
always11–20get_theme_support()
!isset($_wp_theme_features)15–80none
always16–29__(), _doing_it_wrong()
!empty($args) && isset($_wp_theme_features)25array_merge()
always26–38array_intersect_key(), wp_parse_args()
isset($args)28get_post_format_slugs(), array_keys(), array_intersect()
isset($args) && isset($_wp_theme_features)33get_theme_support(), array_merge(), array_unique()
isset($_wp_theme_features)33–39__(), _doing_it_wrong(), array_merge()
$args !== true && !isset($_wp_theme_features)50–86define()
$args !== true && !isset($_wp_theme_features)56–90define(), define()
$args !== true && !isset($_wp_theme_features)62–94define(), define(), define()
2 further outcomes, up to 102 instructions
$args !== true && !isset($_wp_theme_features) && !defined('NO_HEADER_TEXT')69–98define(), define(), define(), define()
$args !== true && !isset($_wp_theme_features) && !defined('NO_HEADER_TEXT') && !defined('HEADER_IMAGE_WIDTH') && !defined('HEADER_IMAGE_HEIGHT') && !defined('HEADER_TEXTCOLOR') && !defined('HEADER_IMAGE')76–102define(), define(), define(), define(), define()

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-dev37310–10254
8.537310–10254
8.437310–10254
8.337310–10254
8.237310–102541 more instruction than PHP 8.1
8.137210–10254
7.437210–10254

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

Used by · 32

Show all 32

Source code

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;

Changelog

Introduced in 2.9.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.

6.6.0
The editor-spacing-sizes feature was added.from the docblock
6.5.0
The appearance-tools feature enables a few design tools for blocks, see WP_Theme_JSON::APPEARANCE_TOOLS_OPT_INS for a complete list.from the docblock
6.3.0
The border feature allows themes without theme.json to add border styles to blocks.from the docblock
6.3.0
The link-color feature allows to enable the link color setting.from the docblock
6.1.0
The disable-layout-styles feature disables the default layout styles.from the docblock
6.1.0
The block-template-parts feature allows to edit any reusable template part from site editor.from the docblock
6.0.0
The html5 feature warns if no array is passed as the second parameter.from the docblock
5.8.0
The block-templates feature indicates whether a theme uses block-based templates.from the docblock
5.8.0
The widgets-block-editor feature enables the Widgets block editor.from the docblock
5.6.0
The post-formats feature warns if no array is passed as the second parameter.from the docblock
5.5.0
The custom-logo feature now also accepts 'unlink-homepage-logo'.from the docblock
5.5.0
The core-block-patterns feature was added and is enabled by default.from the docblock
5.4.0
The disable-custom-gradients feature limits to default gradients or gradients added through editor-gradient-presets theme support.from the docblock
5.3.0
Formalized the existing and already documented ...$args parameter by adding it to the function signature.from the docblock
5.3.0
The html5 feature now also accepts 'script' and 'style'.from the docblock
5.0.0
The responsive-embeds, align-wide, dark-editor-style, disable-custom-colors, disable-custom-font-sizes, editor-color-palette, editor-font-sizes, editor-styles, and wp-block-styles features were added.from the docblock
4.7.0
The starter-content feature was added.from the docblock
4.5.0
The customize-selective-refresh-widgets feature was added.from the docblock
4.1.0
The title-tag feature was added.from the docblock
3.9.0
The html5 feature now also accepts 'gallery' and 'caption'.from the docblock
3.6.1
The html5 feature requires an array of types to be passed. Defaults to 'comment-list', 'comment-form', 'search-form' for backward compatibility.from the docblock
3.6.0
The html5 feature was added.from the docblock
3.4.0
The custom-header-uploads feature was deprecated.from the docblock
2.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/theme.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.