wp_get_themes()
Gets data of all themes (templates) from the "themes" folder. The data is returned as an array of objects: each object is a set of data for a theme.
The speed of the function directly depends on how many themes you have in the "themes" folder. Therefore, for performance reasons, limit yourself to the function wp_get_theme() if possible.
If you just need to get the names of all themes (the names of the theme directories), you can use the function search_theme_directories().
An analogous function for getting plugin data: get_plugins()
No Hooks.
Returns
WP_Theme[]. An array of objects WP_Theme.
Usage
wp_get_themes( $args );
- $args(array)
Array of arguments by which the result will be obtained.
Default: [ 'errors' => false , 'allowed' => null, 'blog_id' => 0 ]
Might accept the following arguments:
-
errors
Might be:- "true" - to return themes with errors.
- "false" - to return themes without errors.
- "null" - to return all themes.
Default: false
-
allowed(multisites)
Might be:- "true" - to return only themes available for the site.
- "false" - to return themes not available for the site.
- "site" - to return themes available for network sites.
- "network" - to return themes available for the network itself.
- "null" - will return all themes.
Default: null
-
blog_id(multisites)
The ID of the blog for which themes are available.Default: 0 (means - current blog)
-
Examples
#1 Get the data of all existing themes
$themes = wp_get_themes();
$themes will contain the following array:
Array ( [twentyfourteen] => WP_Theme Object ( [theme_root:WP_Theme:private] => C:/sites/example.com/www/wp-content/themes [headers:WP_Theme:private] => Array ( [Name] => Twenty Fourteen [ThemeURI] => http://wordpress.org/themes/twentyfourteen [Description] => In 2014, our default theme lets you create a responsive magazine website with a sleek, modern design. Feature your favorite homepage content in either a grid or a slider. Use the three widget areas to customize your website, and change your content's layout with a full-width page template and a contributor page to show off your authors. Creating a magazine website with WordPress has never been easier. [Author] => the WordPress team [AuthorURI] => http://wordpress.org/ [Version] => 1.0 [Template] => [Status] => [Tags] => black, green, white, light, dark, two-columns, three-columns, left-sidebar, right-sidebar, fixed-layout, responsive-layout, custom-background, custom-header, custom-menu, editor-style, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready, accessibility-ready [TextDomain] => twentyfourteen [DomainPath] => ) [headers_sanitized:WP_Theme:private] => [name_translated:WP_Theme:private] => [errors:WP_Theme:private] => [stylesheet:WP_Theme:private] => twentyfourteen [template:WP_Theme:private] => twentyfourteen [parent:WP_Theme:private] => [theme_root_uri:WP_Theme:private] => [textdomain_loaded:WP_Theme:private] => [cache_hash:WP_Theme:private] => c997aa5b2bccf71942eebe3c280effb1 ) [twentythirteen] => WP_Theme Object ( ... ) [twentytwelve] => WP_Theme Object ( ... ) )
Notes
- Global. String[].
$wp_theme_directories
Changelog
| Since 3.4.0 | Introduced. |