Gets a WP_Theme object for a theme.
Parameters
$stylesheet
stringoptional- Directory name for the theme. Defaults to active theme.
Default:
''
$theme_root
stringoptional- Absolute path of the theme root to look in.
If not specified, get_raw_theme_root() is used to calculate the theme root for the $stylesheet provided (or active theme).Default:
''
Return
WP_Theme Theme object. Be sure to check the object’s exists() method if you need to confirm the theme’s existence.Source
function wp_get_theme( $stylesheet = '', $theme_root = '' ) {
global $wp_theme_directories;
if ( empty( $stylesheet ) ) {
$stylesheet = get_stylesheet();
}
if ( empty( $theme_root ) ) {
$theme_root = get_raw_theme_root( $stylesheet );
if ( false === $theme_root ) {
$theme_root = WP_CONTENT_DIR . '/themes';
} elseif ( ! in_array( $theme_root, (array) $wp_theme_directories, true ) ) {
$theme_root = WP_CONTENT_DIR . $theme_root;
}
}
return new WP_Theme( $stylesheet, $theme_root );
}
Related
Uses | Description |
---|---|
get_raw_theme_root()wp-includes/theme.php | Gets the raw theme root relative to the content directory with no filters applied. |
get_stylesheet()wp-includes/theme.php | Retrieves name of the current stylesheet. |
WP_Theme::__construct()wp-includes/class-wp-theme.php | Constructor for WP_Theme. |
Used by | Description |
---|---|
WP_REST_Templates_Controller::get_wp_templates_author_text_field()wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php | Returns a human readable text for the author of the template. |
wp_get_theme_preview_path()wp-includes/theme-previews.php | Filters the blog option to return the path for the previewed theme. |
_register_theme_block_patterns()wp-includes/block-patterns.php | Register any patterns that the active theme may provide under its |
WP_Theme_JSON_Resolver::get_style_variations()wp-includes/class-wp-theme-json-resolver.php | Returns the style variations defined by the theme. |
WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles()wp-includes/class-wp-theme-json-resolver.php | Returns the custom post type that contains the user’s origin config for the active theme or an empty array if none are found. |
WP_Theme_JSON_Resolver::get_user_data()wp-includes/class-wp-theme-json-resolver.php | Returns the user’s origin config. |
WP_Theme_JSON_Resolver::get_user_global_styles_post_id()wp-includes/class-wp-theme-json-resolver.php | Returns the ID of the custom post type that stores user data. |
wp_is_block_theme()wp-includes/theme.php | Returns whether the active theme is a block-based theme or not. |
get_block_theme_folders()wp-includes/block-template-utils.php | For backward compatibility reasons, block themes might be using block-templates or block-template-parts, this function ensures we fallback to these folders properly. |
WP_Theme_JSON_Resolver::get_theme_data()wp-includes/class-wp-theme-json-resolver.php | Returns the theme’s data. |
WP_REST_Server::add_active_theme_link_to_index()wp-includes/rest-api/class-wp-rest-server.php | Adds a link to the active theme for users who have proper permissions. |
WP_REST_Themes_Controller::get_item_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Checks if a given request has access to read the theme. |
WP_REST_Themes_Controller::get_item()wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Retrieves a single theme. |
WP_REST_Themes_Controller::prepare_links()wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Prepares links for the request. |
validate_theme_requirements()wp-includes/theme.php | Validates the theme requirements for WordPress version and PHP version. |
WP_Recovery_Mode_Email_Service::get_debug()wp-includes/class-wp-recovery-mode-email-service.php | Return debug information in an easy to manipulate format. |
WP_Recovery_Mode_Email_Service::get_cause()wp-includes/class-wp-recovery-mode-email-service.php | Gets the description indicating the possible cause for the error. |
WP_Debug_Data::debug_data()wp-admin/includes/class-wp-debug-data.php | Static function for generating site debug data when required. |
WP_Site_Health::get_test_theme_version()wp-admin/includes/class-wp-site-health.php | Tests if themes are outdated, or unnecessary. |
populate_network_meta()wp-admin/includes/schema.php | Creates WordPress network meta and sets the default values. |
WP_REST_Themes_Controller::get_items()wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Retrieves a collection of themes. |
WP_REST_Themes_Controller::prepare_item_for_response()wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Prepares a single theme output for response. |
WP_REST_Posts_Controller::check_template()wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks whether the template is valid for the given post. |
wp_edit_theme_plugin_file()wp-admin/includes/file.php | Attempts to edit a file for a theme or plugin. |
WP_REST_Posts_Controller::handle_template()wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Sets the template for a post. |
wp_ajax_install_theme()wp-admin/includes/ajax-actions.php | Handles installing a theme via AJAX. |
wp_ajax_update_theme()wp-admin/includes/ajax-actions.php | Handles updating a theme via AJAX. |
wp_ajax_delete_theme()wp-admin/includes/ajax-actions.php | Handles deleting a theme via AJAX. |
WP_Theme::get_core_default_theme()wp-includes/class-wp-theme.php | Determines the latest WordPress default theme that is installed. |
WP_Automatic_Updater::update()wp-admin/includes/class-wp-automatic-updater.php | Updates an item, if appropriate. |
Theme_Upgrader::theme_info()wp-admin/includes/class-theme-upgrader.php | Gets the WP_Theme object for a theme. |
Language_Pack_Upgrader::get_name_for_update()wp-admin/includes/class-language-pack-upgrader.php | Gets the name of an item being updated. |
wp_prepare_themes_for_js()wp-admin/includes/theme.php | Prepares themes for JavaScript. |
delete_theme()wp-admin/includes/theme.php | Removes a theme. |
get_page_templates()wp-admin/includes/theme.php | Gets the page templates available in this theme. |
current_theme_info()wp-admin/includes/deprecated.php | Retrieves information on the current active theme. |
WP_Theme_Install_List_Table::_get_theme_status()wp-admin/includes/class-wp-theme-install-list-table.php | Checks to see if the theme is already installed. |
populate_options()wp-admin/includes/schema.php | Create WordPress options and set the default values. |
update_right_now_message()wp-admin/includes/update.php | Displays WordPress version and active theme in the ‘At a Glance’ dashboard widget. |
get_theme_updates()wp-admin/includes/update.php | Retrieves themes with updates available. |
wp_ajax_query_themes()wp-admin/includes/ajax-actions.php | Handles getting themes from themes_api() via AJAX. |
WP_Customize_Manager::theme()wp-includes/class-wp-customize-manager.php | Gets the theme being customized. |
WP_Customize_Manager::__construct()wp-includes/class-wp-customize-manager.php | Constructor. |
check_theme_switched()wp-includes/theme.php | Checks if a theme has been changed and runs ‘after_switch_theme’ hook on the next WP load. |
remove_theme_mods()wp-includes/theme.php | Removes theme modifications option for the active theme. |
switch_theme()wp-includes/theme.php | Switches the theme. |
validate_current_theme()wp-includes/theme.php | Checks that the active theme has the required files. |
get_theme_mods()wp-includes/theme.php | Retrieves all theme modifications. |
get_current_theme()wp-includes/deprecated.php | Retrieve current theme name. |
wp_insert_post()wp-includes/post.php | Inserts or update a post. |
Changelog
Version | Description |
---|---|
3.4.0 | Introduced. |
Echo the name of an installed theme
Result:
Get other data: Text domain & theme URI
Switch a specific theme on all sites in a multisite installation
Get the directory name of the current theme regardless of the child theme.
Code to Display current or any installed theme version:
Display current theme version:
Display any of installed theme version using directory name:
Display the current theme author URI
Display the current theme’s version
Echo the name of the current active theme