get_stylesheet_directory() - WordPress 函数参考中文文档

返回介绍

get_stylesheet_directory()

发布于 2017-09-11 字数3178 浏览 916 评论 0

get_stylesheet_directory()

Retrieve stylesheet directory path for current theme.


描述


返回值

(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 );
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

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.

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!