wppaste
WordPress

current_theme_supports( string $feature, mixed $args ): bool

Since
2.9.0, 5.3.0
Source
wp-includes/theme.php:3159

Determines whether the active theme has declared support for a named feature registered via add_theme_support(). It accepts extra arguments for features like post-thumbnails, post-formats, html5, custom-logo, custom-header and custom-background that were registered with a specific type or capability. When no extra arguments are given it returns true as soon as the feature exists at all, without checking any registered subtype, so pass the type or capability you actually care about to get a meaningful result.

Checks a theme's support for a given feature.

Description

Example usage:

current_theme_supports( 'custom-logo' );
current_theme_supports( 'html5', 'comment-form' );

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

Return value

bool
True if the active theme supports the feature, false otherwise.

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.

Check whether a theme feature supports a specific post type

Register post thumbnail support for two post types, then confirm which ones report support.

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

$supports_page       = current_theme_supports( 'post-thumbnails', 'page' );
$supports_attachment = current_theme_supports( 'post-thumbnails', 'attachment' );

echo 'Pages support thumbnails: ' . esc_html( $supports_page ? 'yes' : 'no' ) . "\n";
echo 'Attachments support thumbnails: ' . esc_html( $supports_attachment ? 'yes' : 'no' ) . "\n";

If add_theme_support() had been called with no array (support for every type), current_theme_supports() would return true for any post type without checking the list.

Check whether a specific post format is registered

Register two custom post formats and confirm which one the active theme reports support for.

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

$supports_aside = current_theme_supports( 'post-formats', 'aside' );
$supports_video = current_theme_supports( 'post-formats', 'video' );

echo 'Aside format supported: ' . esc_html( $supports_aside ? 'yes' : 'no' ) . "\n";
echo 'Video format supported: ' . esc_html( $supports_video ? 'yes' : 'no' ) . "\n";

Common problems and fixes · 4

Why does current_theme_supports() return false right after I call add_theme_support()?

The function looks up the global $_wp_theme_features array directly, so it only sees a feature that has already been registered by the time the check runs. If add_theme_support() fires later than the code calling current_theme_supports(), or on a hook that runs after it, the array key won't exist yet. - Call add_theme_support() on the 'after_setup_theme' hook. - Make sure any plugin code checking support runs on 'init' or later, not earlier than theme setup.

Why does checking a feature always return true even though I only registered it for certain post types?

When you call current_theme_supports() with no second argument, the source skips the switch statement entirely (post-thumbnails, post-formats, html5, custom-logo, custom-header, custom-background all rely on that switch) and returns true as soon as the feature key exists at all.
Pass the specific type or capability as an extra argument, for example current_theme_supports( 'post-thumbnails', 'page' ), to get an accurate answer instead of just confirming the feature was registered.

Why does current_theme_supports('custom-header-uploads') give a strange result?

That feature name is a legacy alias hard-coded in the function: it is rewritten internally to current_theme_supports( 'custom-header', 'uploads' ) before anything else runs, regardless of what you actually registered under 'custom-header-uploads'.
Call current_theme_supports( 'custom-header', 'uploads' ) directly instead of the old alias to avoid confusion about which key is really being checked.

Can a plugin override what current_theme_supports() reports for a feature?

Yes. The function runs its result through the dynamic filter current_theme_supports-{$feature} before returning, both on the early no-args exit and on the final fallback path, so any plugin can hook that filter to force a feature to appear supported or unsupported.
If a theme feature check behaves unexpectedly, search active plugins for a current_theme_supports-{feature} filter callback before assuming the theme itself is misconfigured.

Alternatives and related functions

add_theme_support
When you need to register that the theme supports a feature in the first place, since current_theme_supports() only reads what add_theme_support() has already recorded.
get_theme_support
When you need the actual arguments registered for a feature (such as the array of supported post types) rather than a plain true or false answer.
remove_theme_support
When a child theme or plugin needs to unregister a feature the parent theme declared, so later current_theme_supports() calls return false for it.

Performance profile

How much work a call to current_theme_supports() 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
8–32

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

Plugin surface
1 hook

Third-party callbacks on 'current_theme_supports-{$feature}' run inside this call, and their cost is not bounded by anything here.

Called by
50

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

What it touches

  • hookthird-party callbacksapply_filters()called directly

What one call costs · 3 distinct outcomes

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

WhenInstructionsCalls it makes
$feature !== "custom-header-uploads"8–32none
$feature === "custom-header-uploads"10current_theme_supports()
$feature !== "custom-header-uploads" && isset($_wp_theme_features[$feature])18–32apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev758–3212
8.5758–3212
8.4758–32126 fewer instructions than PHP 8.3
8.3818–3212
8.2818–32121 more instruction than PHP 8.1
8.1808–3312
7.4808–3312

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.

Hooks and filters fired · 2

2 hooks fire while current_theme_supports() runs, in this order:

  1. apply_filters( current_theme_supports-{$feature} )filterline 3173 (+14 into the body)

    Filters whether the active theme supports a specific feature.

  2. apply_filters( current_theme_supports-{$feature} )filterline 3219 (+60 into the body)

    Filters whether the active theme supports a specific feature.

Uses · 2

Used by · 50

Show all 50

Source code

function current_theme_supports( $feature, ...$args ) {	global $_wp_theme_features; 	if ( 'custom-header-uploads' === $feature ) {		return current_theme_supports( 'custom-header', 'uploads' );	} 	if ( ! isset( $_wp_theme_features[ $feature ] ) ) {		return false;	} 	// If no args passed then no extra checks need to be performed.	if ( ! $args ) {		/** This filter is documented in wp-includes/theme.php */		return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores	} 	switch ( $feature ) {		case 'post-thumbnails':			/*			 * post-thumbnails can be registered for only certain content/post types			 * by passing an array of types to add_theme_support().			 * If no array was passed, then any type is accepted.			 */			if ( true === $_wp_theme_features[ $feature ] ) {  // Registered for all types.				return true;			}			$content_type = $args[0];			return in_array( $content_type, $_wp_theme_features[ $feature ][0], true ); 		case 'html5':		case 'post-formats':			/*			 * Specific post formats can be registered by passing an array of types			 * to add_theme_support().			 *			 * Specific areas of HTML5 support *must* be passed via an array to add_theme_support().			 */			$type = $args[0];			return in_array( $type, $_wp_theme_features[ $feature ][0], true ); 		case 'custom-logo':		case 'custom-header':		case 'custom-background':			// Specific capabilities can be registered by passing an array to add_theme_support().			return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] );	} 	/**	 * Filters whether the active theme supports a specific feature.	 *	 * The dynamic portion of the hook name, `$feature`, refers to the specific	 * theme feature. See add_theme_support() for the list of possible values.	 *	 * @since 3.4.0	 *	 * @param bool   $supports Whether the active theme supports the given feature. Default true.	 * @param array  $args     Array of arguments for the feature.	 * @param string $feature  The theme feature.	 */	return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores}

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.

5.3.0
Formalized the existing and already documented ...$args parameter by adding it to the function signature.from the docblock
2.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.