返回介绍

wp_get_theme()

发布于 2017-09-11 12:09:24 字数 5800 浏览 1065 评论 0 收藏 0

wp_get_theme( string $stylesheet = null,  string $theme_root = null )

Gets a WP_Theme object for a theme.


description


参数

$stylesheet

(string) (Optional) Directory name for the theme. Optional. Defaults to current theme.

Default value: null

$theme_root

(string) (Optional) Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() is used to calculate the theme root for the $stylesheet provided (or current theme).

Default value: null


返回值

(WP_Theme) Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.


源代码

File: wp-includes/theme.php

function wp_get_theme( $stylesheet = null, $theme_root = null ) {
	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 ) )
			$theme_root = WP_CONTENT_DIR . $theme_root;
	}

	return new WP_Theme( $stylesheet, $theme_root );
}

更新日志

Versiondescription
3.4.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: get_raw_theme_root()
  • wp-includes/theme.php: get_stylesheet()
  • wp-includes/class-wp-theme.php: WP_Theme::__construct()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::get_item_schema()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::handle_template()
  • wp-admin/includes/ajax-actions.php: wp_ajax_install_theme()
  • wp-admin/includes/ajax-actions.php: wp_ajax_update_theme()
  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_theme()
  • wp-includes/class-wp-theme.php: WP_Theme::get_core_default_theme()
  • wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::update()
  • wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::theme_info()
  • wp-admin/includes/class-language-pack-upgrader.php: Language_Pack_Upgrader::get_name_for_update()
  • wp-admin/includes/theme.php: wp_prepare_themes_for_js()
  • wp-admin/includes/theme.php: get_page_templates()
  • wp-admin/includes/deprecated.php: current_theme_info()
  • wp-admin/includes/schema.php: populate_network()
  • wp-admin/includes/class-wp-theme-install-list-table.php: WP_Theme_Install_List_Table::_get_theme_status()
  • wp-admin/includes/schema.php: populate_options()
  • wp-admin/includes/update.php: update_right_now_message()
  • wp-admin/includes/update.php: get_theme_updates()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::register_controls()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::theme()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::__construct()
  • wp-includes/theme.php: check_theme_switched()
  • wp-includes/theme.php: remove_theme_mods()
  • wp-includes/theme.php: switch_theme()
  • wp-includes/theme.php: validate_current_theme()
  • wp-includes/theme.php: get_theme_mods()
  • wp-includes/deprecated.php: get_current_theme()
  • wp-includes/post.php: wp_insert_post()
  • Show 22 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Get other data: Text domain & theme URI

    
    <?php
    $my_theme = wp_get_theme();
    echo esc_html( $my_theme->get( 'TextDomain' ) );
    echo esc_html( $my_theme->get( 'ThemeURI' ) );
    ?>
    
    
  2. Echo the name of an installed theme

    
    <?php
    $my_theme = wp_get_theme( 'twentytwelve' );
    if ( $my_theme->exists() )
    	echo esc_html( $my_theme );
    ?>
    
    

    Display the current theme’s version

    
    $my_theme = wp_get_theme();
    printf( "%1$s is version %2$s",
    	$my_theme->get( 'Name' ),
    	$my_theme->get( 'Version' )
    );
    

    Display the current theme author URI

    
    $my_theme = wp_get_theme();
    echo esc_html( $my_theme->get( 'AuthorURI' ) );
    

    Echo the name of the current active theme

    
    <?php
    echo wp_get_theme();
    ?>
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文