wppaste
WordPress

get_theme_support( string $feature, mixed $args ): mixed

Since
3.1.0, 5.3.0
Source
wp-includes/theme.php:3042

Retrieves the value or extra arguments a theme (or plugin) passed to add_theme_support() for a given feature. Returns false when the feature was never registered, so callers should not assume a truthy result. Pair it with current_theme_supports() when you only need a yes/no answer rather than the stored data.

Gets the theme support arguments passed when registering that support.

Description

Example usage:

get_theme_support( 'custom-logo' );
get_theme_support( 'custom-header', 'width' );

Compatibility

WordPress
since 5.3.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 to check. See add_theme_support() for the list of possible values.
$argsmixed
Optional extra arguments to be checked against certain features.

Return value

mixed
The array of extra arguments or the value for the registered feature.

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Read the width configured with add_theme_support('custom-header')

Register custom header support with explicit dimensions, then pull out just the width.

add_theme_support( 'custom-header', array(
	'width'       => 1200,
	'height'      => 280,
	'flex-height' => true,
) );

$header_width = get_theme_support( 'custom-header', 'width' );

echo esc_html( 'Registered custom header width: ' . $header_width );

The second argument only works for custom-logo, custom-header and custom-background because those are the only features get_theme_support() special-cases.

List the post types a theme enabled for post thumbnails

Register post-thumbnails support for two post types and inspect the stored value.

add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );

$post_thumbnail_support = get_theme_support( 'post-thumbnails' );

print_r( $post_thumbnail_support );

For features other than custom-logo, custom-header and custom-background, the whole stored array is returned as passed to add_theme_support().

Common problems and fixes · 3

Why does get_theme_support() return false for a feature I definitely registered?

The function only checks the global $_wp_theme_features array, so it returns false whenever the feature key is missing there, either because add_theme_support() has not run yet at the point you call it, or the slug is misspelled.

How do I know if a feature is unsupported versus its value legitimately being false?

The source returns false both when $feature is not set in $_wp_theme_features and, for custom-logo, custom-header and custom-background, when the requested key is missing (via the ?? false fallback). There is no way to tell these apart from the return value alone.

Why is the array I get back nested one level deeper than what I passed to add_theme_support()?

add_theme_support() stores its variadic arguments as an array, so the arguments you passed sit at index 0 of the stored value, exactly why the source reaches into $_wp_theme_features[ $feature ][0][ $args[0] ] for the special-cased features.

Alternatives and related functions

current_theme_supports
When you only need to know whether a feature is enabled and do not care about the extra arguments it was registered with.
add_theme_support
When you are the one registering the feature and its arguments rather than reading them back later.
remove_theme_support
When a child theme or plugin needs to unregister a feature a parent theme already added.

Performance profile

How much work a call to get_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
6–23

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
50

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

What one call costs · 1 distinct outcome

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

WhenInstructionsCalls it makes
always6–23none

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 29 instructions, 6–23 executed per call, 7 branches. The work does not change between versions.

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.

Used by · 50

Show all 50

Source code

function get_theme_support( $feature, ...$args ) {	global $_wp_theme_features; 	if ( ! isset( $_wp_theme_features[ $feature ] ) ) {		return false;	} 	if ( ! $args ) {		return $_wp_theme_features[ $feature ];	} 	switch ( $feature ) {		case 'custom-logo':		case 'custom-header':		case 'custom-background':			if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) {				return $_wp_theme_features[ $feature ][0][ $args[0] ];			}			return false; 		default:			return $_wp_theme_features[ $feature ];	}}

Changelog

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

5.3.0
Formalized the existing and already documented ...$args parameter by adding it to the function signature.from the docblock
3.1.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.