返回介绍

get_stylesheet_directory()

发布于 2017-09-11 00:14:37 字数 3175 浏览 1040 评论 0 收藏 0

get_stylesheet_directory()

Retrieve stylesheet directory path for current theme.


description


返回值

(string) Path to current theme directory.


源代码

File: wp-includes/theme.php

function get_stylesheet_directory() {
	$stylesheet = get_stylesheet();
	$theme_root = get_theme_root( $stylesheet );
	$stylesheet_dir = "$theme_root/$stylesheet";

	/**
	 * Filters the stylesheet directory path for current theme.
	 *
	 * @since 1.5.0
	 *
	 * @param string $stylesheet_dir Absolute path to the current theme.
	 * @param string $stylesheet     Directory name of the current theme.
	 * @param string $theme_root     Absolute path to themes directory.
	 */
	return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: get_theme_root()
  • wp-includes/theme.php: stylesheet_directory
  • wp-includes/theme.php: get_stylesheet()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::prepare_starter_content_attachments()
  • wp-includes/link-template.php: get_theme_file_path()
  • wp-includes/link-template.php: get_theme_file_uri()
  • wp-includes/theme.php: get_editor_stylesheets()
  • wp-includes/theme.php: validate_current_theme()
  • wp-includes/theme.php: get_locale_stylesheet_uri()
  • wp-includes/l10n.php: load_child_theme_textdomain()
  • wp-includes/default-constants.php: wp_templating_constants()
  • Show 3 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

    Basic Example

    Include a PHP file

    
    <?php include( get_stylesheet_directory() . '/includes/myfile.php' ); ?>
    
  2. get_stylesheet_directory() retrieves the child-theme’s directory.
    If you want to retrieve the parent-theme’s directory use get_template_directory() instead or even better loacate_template() – This way Wordpress automatically uses your child themes directory to look for your re源代码 – if there is a child-theme-file present it will use this one instead. No need for enqueuing anything.

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

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

发布评论

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