The current_theme_supports() WordPress PHP function checks if the current theme supports a given feature. This is handy when you need to conditionally add functionality based on theme support.
Usage
To check if a theme supports a feature such as ‘custom-logo’, you can do something like this:
if (current_theme_supports('custom-logo')) { // The theme supports custom logos. }
Parameters
- $feature (string): The feature being checked. See add_theme_support() for the list of possible values.
- $args (mixed): Optional extra arguments to be checked against certain features.
More information
See WordPress Developer Resources: current_theme_supports()
This function has been implemented since WordPress version 2.9.0. It is not deprecated and you can find the source code in wp-includes/theme.php.
Examples
Checking Custom Logo Support
Let’s say you want to display a custom logo if the theme supports it:
if (current_theme_supports('custom-logo')) { the_custom_logo(); }
This will display the custom logo if the theme supports it.
Checking HTML5 Support
You may want to use HTML5 elements in the comment form if the theme supports it:
if (current_theme_supports('html5', 'comment-form')) { // Use HTML5 markup for the comment form. }
This checks if the theme supports HTML5 markup for the comment form.
Checking Post Thumbnails Support
You might want to display post thumbnails only if the theme supports it:
if (current_theme_supports('post-thumbnails')) { the_post_thumbnail(); }
This displays the post thumbnail if the theme supports it.
Checking Custom Header Support
In a case where you want to add a custom header only if the theme supports it:
if (current_theme_supports('custom-header')) { // Add a custom header. }
This adds a custom header if the theme supports it.
Checking Responsive Embeds Support
If you want to use responsive embeds and need to check if the theme supports it:
if (current_theme_supports('responsive-embeds')) { // Use responsive embeds. }
This enables you to use responsive embeds if the theme supports it.