current_theme_supports()WP 2.9.0

Checks if the theme supports the specified feature, registered via add_theme_support().

For features that take arguments (e.g., 'html5' or 'custom-logo'), additional values can be passed to ensure that they are specifically supported.

Must be called after the theme support is declared, usually after the after_setup_theme hook.

Use the filter current_theme_supports-(feature) when you need to disable or enable support under certain conditions.

1 time — 0.000013 sec (very fast) | 50000 times — 0.01 sec (speed of light) | PHP 7.0.8, WP 4.6.1
Hooks from the function

Returns

true|false. true if the theme supports the specified feature, otherwise false.

Usage

if( current_theme_supports( $feature ) ){
	 // feature $feature is enabled...
}
$feature(string) (required)

Name of the feature to check. Available list:

...$args(mixed)

Additional arguments for the specific feature that also need to be checked.

When a theme declares support for an option with sub-items, it passes an array of these sub-items:

add_theme_support( 'html5', [ 'comment-form', 'comment-list' ] );

The function behaves as follows:

  • Without arguments - it is sufficient that the html5 feature is supported:

    current_theme_supports( 'html5' ); // true
  • With arguments - the function checks each passed sub-item. If at least one is not supported, it will return false. true will only be returned when all specified sub-items are supported.

    current_theme_supports( 'html5', 'comment-form' );   // true
    current_theme_supports( 'html5', 'search-form' );    // false
    current_theme_supports( 'html5', 'comment-form', 'search-form' ); // false

By default: none

Examples

0

#1 Demo

Let's check if the feature is enabled:

if( current_theme_supports('custom-header') ){
	 // Do something special if the custom-header feature is enabled...
}

Checking a specific argument of HTML5 support:

if ( current_theme_supports( 'html5', 'comment-form' ) ) {
	// Load styles or execute logic that requires HTML5 markup for the comment form
}

Notes

  • Global. Array. $_wp_theme_features

Changelog

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

current_theme_supports() code WP 7.0

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
}