Using WordPress ‘all_themes’ PHP filter

The all_themes WordPress PHP filter allows you to modify the full array of WP_Theme objects that are displayed in the Multisite themes list table.

Usage

add_filter('all_themes', 'your_custom_function');
function your_custom_function($all_themes) {
    // your custom code here
    return $all_themes;
}

Parameters

  • $all_themes (WP_Theme[]): Array of WP_Theme objects to display in the list table.

More information

See WordPress Developer Resources: all_themes

Examples

Remove specific theme from the list

Remove the ‘Twenty Twenty-One’ theme from the themes list.

add_filter('all_themes', 'remove_twenty_twenty_one_theme');
function remove_twenty_twenty_one_theme($all_themes) {
    unset($all_themes['twentytwentyone']);
    return $all_themes;
}

Display only child themes

Show only child themes in the themes list.

add_filter('all_themes', 'display_only_child_themes');
function display_only_child_themes($all_themes) {
    foreach ($all_themes as $key => $theme) {
        if (!$theme->parent()) {
            unset($all_themes[$key]);
        }
    }
    return $all_themes;
}

Display themes with a minimum rating

Display themes with a minimum rating of 4 stars.

add_filter('all_themes', 'display_min_rating_themes');
function display_min_rating_themes($all_themes) {
    $min_rating = 4;
    foreach ($all_themes as $key => $theme) {
        if ($theme->get('rating') < $min_rating) {
            unset($all_themes[$key]);
        }
    }
    return $all_themes;
}

Sort themes by the number of downloads

Sort the themes list by the number of downloads in descending order.

add_filter('all_themes', 'sort_themes_by_downloads');
function sort_themes_by_downloads($all_themes) {
    uasort($all_themes, function ($a, $b) {
        return $b->get('downloaded') - $a->get('downloaded');
    });
    return $all_themes;
}

Add custom data to theme objects

Add custom data (e.g., ‘is_featured’) to the theme objects in the themes list.

add_filter('all_themes', 'add_custom_data_to_themes');
function add_custom_data_to_themes($all_themes) {
    foreach ($all_themes as $key => $theme) {
        $theme->is_featured = $key === 'featured-theme-slug';
    }
    return $all_themes;
}