The get_themes() WordPress PHP function retrieves a list of themes with their theme data in the theme directory.
Usage
Here’s a generic example of how to use the function:
$themes = get_themes();
Parameters
This function does not have any parameters.
More information
See WordPress Developer Resources: get_themes()
Examples
Display a list of theme names
This example retrieves all themes and displays their names:
$themes = get_themes();
foreach ($themes as $theme) {
echo $theme['Name'] . '<br>';
}
Check if a specific theme is installed
This example checks if the theme ‘Twenty Twenty’ is installed:
$themes = get_themes();
$theme_name = 'Twenty Twenty';
if (array_key_exists($theme_name, $themes)) {
echo 'Theme ' . $theme_name . ' is installed.';
} else {
echo 'Theme ' . $theme_name . ' is not installed.';
}
Display the current theme’s information
This example retrieves and displays the current theme’s information:
$current_theme = wp_get_theme();
$themes = get_themes();
echo 'Current theme: ' . $current_theme->get('Name') . '<br>';
echo 'Version: ' . $current_theme->get('Version') . '<br>';
echo 'Author: ' . $current_theme->get('Author') . '<br>';
echo 'Description: ' . $current_theme->get('Description') . '<br>';
Display themes with a specific tag
This example displays all themes with the ‘responsive-layout’ tag:
$themes = get_themes();
$tag = 'responsive-layout';
foreach ($themes as $theme) {
if (in_array($tag, $theme['Tags'])) {
echo $theme['Name'] . '<br>';
}
}
Count the number of installed themes
This example counts and displays the total number of installed themes:
$themes = get_themes(); $count = count($themes); echo 'Total installed themes: ' . $count;