require_if_theme_supports( string $feature, string $file ): bool

In this article

Checks a theme’s support for a given feature before loading the functions which implement it.

Parameters

$featurestringrequired
The feature being checked. See add_theme_support() for the list of possible values.
More Arguments from add_theme_support( … $feature )The feature being added. Likely core values include:
  • 'admin-bar'
  • 'align-wide'
  • 'appearance-tools'
  • 'automatic-feed-links'
  • 'block-templates'
  • 'block-template-parts'
  • 'border'
  • 'core-block-patterns'
  • 'custom-background'
  • 'custom-header'
  • 'custom-line-height'
  • 'custom-logo'
  • 'customize-selective-refresh-widgets'
  • 'custom-spacing'
  • 'custom-units'
  • 'dark-editor-style'
  • 'disable-custom-colors'
  • 'disable-custom-font-sizes'
  • 'disable-custom-gradients'
  • 'disable-layout-styles'
  • 'editor-color-palette'
  • 'editor-gradient-presets'
  • 'editor-font-sizes'
  • 'editor-spacing-sizes'
  • 'editor-styles'
  • 'featured-content'
  • 'html5'
  • 'link-color'
  • 'menus'
  • 'post-formats'
  • 'post-thumbnails'
  • 'responsive-embeds'
  • 'starter-content'
  • 'title-tag'
  • 'widgets'
  • 'widgets-block-editor'
  • 'wp-block-styles'
$filestringrequired
Path to the file.

Return

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

Source

function require_if_theme_supports( $feature, $file ) {
	if ( current_theme_supports( $feature ) ) {
		require $file;
		return true;
	}
	return false;
}

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.