get_theme_support()
Gets the arguments of the specified feature that were passed when registering this feature for the theme (template).
The theme feature is registered by the function add_theme_support() and sometimes parameters are passed during registration. get_theme_support() retrieves the passed arguments.
All features are stored in the global variable $_wp_theme_features.
1 time — 0.000015 sec (very fast) | 50000 times — 0.02 sec (speed of light)
No Hooks.
Returns
Mixed. Array/string/int/object. An array of arguments or the value of the registered feature.
Usage
get_theme_support( $feature );
- $feature(string) (required)
- The feature whose arguments need to be retrieved.
Examples
#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] => ) )
#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 ) */
#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. |