The require_if_theme_supports() WordPress PHP function checks a theme’s support for a given feature before loading the functions which implement it.
Usage
require_if_theme_supports( $feature, $file );
Example:
require_if_theme_supports( 'post-thumbnails', 'inc/post-thumbnails.php' );
Parameters
$feature
(string) (Required) – The feature being checked. Seeadd_theme_support()
for the list of possible values.$file
(string) (Required) – Path to the file.
More information
See WordPress Developer Resources: require_if_theme_supports
Examples
Load custom background functions
Load custom background functions if the theme supports custom backgrounds.
require_if_theme_supports( 'custom-background', 'inc/custom-background.php' );
Load custom logo functions
Load custom logo functions if the theme supports custom logos.
require_if_theme_supports( 'custom-logo', 'inc/custom-logo.php' );
Load custom header functions
Load custom header functions if the theme supports custom headers.
require_if_theme_supports( 'custom-header', 'inc/custom-header.php' );
Load HTML5 support functions
Load HTML5 support functions if the theme supports HTML5.
require_if_theme_supports( 'html5', 'inc/html5.php' );
Load post format functions
Load post format functions if the theme supports post formats.
require_if_theme_supports( 'post-formats', 'inc/post-formats.php' );