Using WordPress ‘allowed_themes’ PHP filter

The allowed_themes WordPress PHP filter allows you to modify the array of themes that are allowed on your network.

Usage

add_filter('allowed_themes', 'your_custom_function');
function your_custom_function($allowed_themes) {
    // your custom code here

    return $allowed_themes;
}

Parameters

  • $allowed_themes (string[]): An array of theme stylesheet names.

More information

See WordPress Developer Resources: allowed_themes

Examples

Allow a specific theme

Allow the ‘twentytwentyone’ theme on the network.

add_filter('allowed_themes', 'allow_twentytwentyone_theme');
function allow_twentytwentyone_theme($allowed_themes) {
    $allowed_themes['twentytwentyone'] = true;
    return $allowed_themes;
}

Disallow a specific theme

Disallow the ‘twentynineteen’ theme on the network.

add_filter('allowed_themes', 'disallow_twentynineteen_theme');
function disallow_twentynineteen_theme($allowed_themes) {
    unset($allowed_themes['twentynineteen']);
    return $allowed_themes;
}

Allow only a list of specific themes

Allow only ‘twentytwenty’ and ‘twentytwentyone’ themes on the network.

add_filter('allowed_themes', 'allow_only_specific_themes');
function allow_only_specific_themes($allowed_themes) {
    return array(
        'twentytwenty' => true,
        'twentytwentyone' => true,
    );
}

Allow themes based on a condition

Allow a theme only if the current user is an administrator.

add_filter('allowed_themes', 'allow_theme_for_admin');
function allow_theme_for_admin($allowed_themes) {
    if (current_user_can('manage_options')) {
        $allowed_themes['my_custom_theme'] = true;
    }
    return $allowed_themes;
}

Allow all themes except a specific one

Allow all themes except the ‘twentynineteen’ theme on the network.

add_filter('allowed_themes', 'disallow_specific_theme');
function disallow_specific_theme($allowed_themes) {
    if (isset($allowed_themes['twentynineteen'])) {
        unset($allowed_themes['twentynineteen']);
    }
    return $allowed_themes;
}