wp_get_theme( string $stylesheet = '', string $theme_root = '' ): WP_Theme
Gets a WP_Theme object for a theme.
Parameters
-
$stylesheet
string Optional -
Directory name for the theme. Defaults to active theme.
Default:
''
-
$theme_root
string Optional -
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
File: wp-includes/theme.php
.
View all references
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
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
Used By | Description |
---|---|
_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_REST_Global_Styles_Controller::get_theme_items() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php |
Returns the given theme global styles variations. |
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 a void 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_REST_Global_Styles_Controller::get_theme_item() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php |
Returns the given theme global styles config. |
wp_is_block_theme() wp-includes/theme.php |
Returns whether the active theme is a block-based theme or not. |
wp_set_unique_slug_on_create_template_part() wp-includes/theme-templates.php |
Sets a custom slug when creating auto-draft template parts. |
get_block_file_template() wp-includes/block-template-utils.php |
Retrieves a unified template object based on a theme file. |
_inject_theme_attribute_in_block_template_content() wp-includes/block-template-utils.php |
Parses wp_template content and injects the active theme’s stylesheet as a theme attribute into each wp_template_part |
_build_block_template_result_from_file() wp-includes/block-template-utils.php |
Builds a unified template object based on a theme file. |
_build_block_template_result_from_post() wp-includes/block-template-utils.php |
Builds a unified template object based a post Object. |
WP_Theme_JSON_Resolver::get_theme_data() wp-includes/class-wp-theme-json-resolver.php |
Returns the theme’s data. |
WP_REST_Templates_Controller::prepare_item_for_database() wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php |
Prepares a single template for create or update. |
wp_filter_wp_template_unique_post_slug() wp-includes/theme-templates.php |
Generates a unique slug for templates. |
resolve_block_template() wp-includes/block-template.php |
Returns the correct ‘wp_template’ to render for the request template type. |
get_block_templates() wp-includes/block-template-utils.php |
Retrieves a list of unified template objects based on a query. |
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 |
Ajax handler for installing a theme. |
wp_ajax_update_theme() wp-admin/includes/ajax-actions.php |
Ajax handler for updating a theme. |
wp_ajax_delete_theme() wp-admin/includes/ajax-actions.php |
Ajax handler for deleting a theme. |
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 |
Get the WP_Theme object for a theme. |
Language_Pack_Upgrader::get_name_for_update() wp-admin/includes/class-language-pack-upgrader.php |
Get the name of an item being updated. |
wp_prepare_themes_for_js() wp-admin/includes/theme.php |
Prepares themes for JavaScript. |
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 |
Check 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 |
Ajax handler for getting themes from themes_api() . |
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. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
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.
Display the current theme author URI
Display the current theme’s version
Top ↑
Feedback
This doesn’t work. You need to $my_theme = wp_get_theme(); echo “; print_r($my_theme); echo “; To output the name and version, you need to do: echo $my_theme[‘Name’]; echo $my_theme[‘Version’]; — By ashkanahmadi —
Echo the name of the current active theme