Using WordPress ‘get_registered_theme_features()’ PHP function

The get_registered_theme_features() WordPress PHP function retrieves a list of registered theme features.

Usage

$registered_theme_features = get_registered_theme_features();

Parameters

  • None

More information

See WordPress Developer Resources: get_registered_theme_features()

Examples

Display the list of registered theme features

This code snippet retrieves the list of registered theme features and displays them in an unordered list.

$registered_theme_features = get_registered_theme_features();

echo '<ul>';
foreach ($registered_theme_features as $feature) {
    echo '<li>' . $feature . '</li>';
}
echo '</ul>';

Check if a specific feature is registered

This code snippet checks if the ‘post-thumbnails’ feature is registered for the current theme.

$registered_theme_features = get_registered_theme_features();

if (in_array('post-thumbnails', $registered_theme_features)) {
    echo 'Post thumbnails are supported.';
} else {
    echo 'Post thumbnails are not supported.';
}

Count the number of registered theme features

This code snippet counts the number of registered theme features and displays the result.

$registered_theme_features = get_registered_theme_features();
$count = count($registered_theme_features);

echo 'The theme has ' . $count . ' registered features.';

Register a new theme feature if not registered

This code snippet registers a new theme feature, ‘custom-header’, if it’s not already registered.

$registered_theme_features = get_registered_theme_features();

if (!in_array('custom-header', $registered_theme_features)) {
    add_theme_support('custom-header');
    echo 'The custom-header feature has been registered.';
} else {
    echo 'The custom-header feature is already registered.';
}

Remove a registered theme feature

This code snippet removes a registered theme feature, ‘custom-background’, if it’s registered.

$registered_theme_features = get_registered_theme_features();

if (in_array('custom-background', $registered_theme_features)) {
    remove_theme_support('custom-background');
    echo 'The custom-background feature has been removed.';
} else {
    echo 'The custom-background feature is not registered.';
}