get_theme_support( string $feature, mixed $args ): mixed
- Since
- 3.1.0, 5.3.0
- Source
wp-includes/theme.php:3030
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.
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?
- How do I know if a feature is unsupported versus its value legitimately being false?
- Why is the array I get back nested one level deeper than what I passed to add_theme_support()?
Why does get_theme_support() return false for a feature I definitely registered?
How do I know if a feature is unsupported versus its value legitimately being false?
Why is the array I get back nested one level deeper than what I passed to add_theme_support()?
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
- Scaling
- Constant
- Instructions
- 6–23
- Plugin surface
- None
- Called by
- 50
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 29.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–23 | none |
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
- Custom_Background::admin_page()Displays the custom background page.
- Custom_Image_Header::get_default_header_images()Gets the details of default header images if defined.
- Custom_Image_Header::get_header_dimensions()Calculates width and height based on what the currently selected theme supports.
- Custom_Image_Header::js_1()Displays JavaScript based on Step 1 and 3.
- Custom_Image_Header::js_2()Displays JavaScript based on Step 2.
- Custom_Image_Header::reset_header_image()Resets a header image to the default image for the theme.
- Custom_Image_Header::step_1()Displays first step of custom header image page.
- Custom_Image_Header::step_2()Displays second step of custom header image page.
- Featured_Content::init()Conditionally hook into WordPress.
- Twenty_Twenty_One_Customize::register()Register customizer options.
- WP_Admin_Bar::initialize()Initializes the admin bar.
- WP_Customize_Background_Image_Control::enqueue()Enqueue control related scripts/styles.
Show all 50
- WP_Customize_Header_Image_Control::enqueue()
- WP_Customize_Header_Image_Control::render_content()
- WP_Customize_Header_Image_Setting::update()
- WP_Customize_Manager::_sanitize_header_textcolor()Callback for validating the header_textcolor value.
- WP_Customize_Manager::register_controls()Registers some default controls.
- WP_Posts_List_Table::inline_edit()Outputs the hidden row displayed when inline editing
- WP_REST_Themes_Controller::prepare_item_for_response()Prepares a single theme output for response.
- _custom_background_cb()Default custom background callback.
- _custom_header_background_just_in_time()Registers the internal custom header and background routines.
- _custom_logo_header_styles()Adds CSS to hide header text for custom logo, based on Customizer setting.
- _delete_site_logo_on_remove_theme_mods()Deletes the site logo when all theme mods are being removed.
- _load_remote_block_patterns()Register Core's official patterns from wordpress.org/patterns.
- _load_remote_featured_patterns()Register `Featured` (category) patterns from wordpress.org/patterns.
- _register_core_block_patterns_and_categories()Registers the core block patterns and categories.
- _remove_theme_support()Do not use. Removes theme support internally without knowledge of those not used by themes directly.
- add_theme_support()Registers theme support for a given feature.
- display_header_text()Whether to display the header text.
- get_background_color()Retrieves value for custom background color.
- get_background_image()Retrieves background image for custom background.
- get_body_class()Retrieves an array of the class names for the body element.
- get_classic_theme_supports_block_editor_settings()Returns the classic theme supports settings for block editor.
- get_custom_header()Gets the header image data.
- get_custom_logo()Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
- get_default_block_editor_settings()Returns the default block editor settings.
- get_header_image()Retrieves header image for custom header.
- get_header_textcolor()Retrieves the custom header text color in 3- or 6-digit hexadecimal form.
- get_media_states()Retrieves an array of media states from an attachment.
- get_theme_starter_content()Expands a theme's starter content configuration using core-provided data.
- is_header_video_active()Checks whether the custom header video is eligible to show on the current page.
- is_random_header_image()Checks if random header image is in use.
- post_format_meta_box()Displays post format form elements.
- twentyfourteen_header_style()Styles the header image and text displayed on the blog
- twentyseventeen_header_style()Styles the header image and text displayed on the blog.
- twentythirteen_header_style()Style the header text displayed on the blog.
- twentytwelve_admin_header_style()Style the header image displayed on the Appearance > Header admin panel.
- twentytwelve_header_style()Style the header text displayed on the blog.
- twentytwenty_block_editor_settings()Block Editor Settings.
- wp_enqueue_admin_bar_bump_styles()Enqueues inline bump styles to make room for the admin bar.
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.
Signature, return type and hooks compared across 5 parsed releases.
...$args parameter by adding it to the function signature.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.