get_theme_support()WP 3.1.0

Gets the theme support arguments passed when registering that support.

Example usage:

get_theme_support( 'custom-logo' );
get_theme_support( 'custom-header', 'width' );
1 time — 0.000015 sec (very fast) | 50000 times — 0.02 sec (speed of light)

No Hooks.

Return

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

Usage

get_theme_support( $feature, ...$args );
$feature(string) (required)
The feature to check. See add_theme_support() for the list of possible values.
...$args(mixed) (required)
Optional extra arguments to be checked against certain features.

Examples

0

#1 Get the arguments of the capability

Get the arguments of the 'html5' theme capability:

$args = get_theme_support( 'html5' );

print_r( $args );
/* will output:
Array
(
	[0] => Array
		(
			[0] => comment-list
			[1] => comment-form
			[2] => search-form
			[3] => gallery
			[4] => caption
		)

)
*/

Gets the custom-background theme support arguments:

$theme_support = get_theme_support( 'custom-background' );

Will conatins:

Array
(
	[0] => Array
		(
			[default-image] =>
			[default-repeat] => repeat
			[default-position-x] => left
			[default-attachment] => scroll
			[default-color] => ffffff
			[wp-head-callback] => _custom_background_cb
			[admin-head-callback] =>
			[admin-preview-callback] =>
		)

)
0

#2 What does variable $_wp_theme_features look like:

global $_wp_theme_features;

print_r( $_wp_theme_features );
/* will output:
Array
(
	[menus] => 1
	[post-thumbnails] => 1
	[html5] => Array
		(
			[0] => Array
				(
					[0] => comment-list
					[1] => comment-form
					[2] => search-form
					[3] => gallery
					[4] => caption
				)

		)

	[widgets] => 1
)
*/
0

#3 post-thumbnails capability

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

// Now there can be two options 
// Depends on how the opportunity was registered

// if it was registered without parameters:
// add_theme_support( 'post-thumbnails' );
// $supports will be true

// if with parameters 
// add_theme_support( 'post-thumbnails', array('post', 'page') ); 
// $supports will be equal to this array
/*
Array
(
	[0] => Array
		(
			[0] => post
			[1] => page
		)

)
*/

Notes

  • Global. Array. $_wp_theme_features

Changelog

Since 3.1.0 Introduced.
Since 5.3.0 Formalized the existing and already documented ...$args parameter by adding it to the function signature.

get_theme_support() code WP 6.5.4

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 ];
	}
}