Using WordPress ‘get_site_allowed_themes()’ PHP function

The get_site_allowed_themes() WordPress PHP function retrieves a list of network-enabled themes. This function is deprecated, so it is recommended to use WP_Theme::get_allowed_on_network() instead.

Usage

Here’s a generic example of how to use the function:

$allowed_themes = get_site_allowed_themes();
print_r($allowed_themes);

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: get_site_allowed_themes()

This function is deprecated in favor of WP_Theme::get_allowed_on_network().

Examples

Retrieve network-enabled themes

This example retrieves the list of network-enabled themes and prints it.

$allowed_themes = get_site_allowed_themes();
print_r($allowed_themes);

Check if a specific theme is network-enabled

This example checks if the ‘twentytwentyone’ theme is network-enabled.

$allowed_themes = get_site_allowed_themes();
$theme_slug = 'twentytwentyone';

if (array_key_exists($theme_slug, $allowed_themes)) {
    echo "The $theme_slug theme is network-enabled.";
} else {
    echo "The $theme_slug theme is not network-enabled.";
}

Display theme names of network-enabled themes

This example retrieves the list of network-enabled themes and prints their names.

$allowed_themes = get_site_allowed_themes();

foreach ($allowed_themes as $theme_slug => $theme_name) {
    echo "Theme: $theme_name ($theme_slug)<br />";
}

Count network-enabled themes

This example retrieves the number of network-enabled themes and prints the result.

$allowed_themes = get_site_allowed_themes();
$theme_count = count($allowed_themes);
echo "There are $theme_count network-enabled themes.";

Switch to a network-enabled theme

This example switches to a network-enabled theme if it exists and is allowed on the site.

$theme_slug = 'twentytwentyone';
$allowed_themes = get_site_allowed_themes();

if (array_key_exists($theme_slug, $allowed_themes)) {
    switch_theme($theme_slug);
    echo "The theme has been switched to $theme_slug.";
} else {
    echo "The $theme_slug theme is not network-enabled.";
}