返回介绍

get_template_directory()

发布于 2017-09-11 00:19:46 字数 3374 浏览 1004 评论 0 收藏 0

get_template_directory()

Retrieve current theme directory.


description


返回值

(string) Template directory path.


源代码

File: wp-includes/theme.php

function get_template_directory() {
	$template = get_template();
	$theme_root = get_theme_root( $template );
	$template_dir = "$theme_root/$template";

	/**
	 * Filters the current theme directory path.
	 *
	 * @since 1.5.0
	 *
	 * @param string $template_dir The URI of the current theme directory.
	 * @param string $template     Directory name of the current theme.
	 * @param string $theme_root   Absolute path to the themes directory.
	 */
	return apply_filters( 'template_directory', $template_dir, $template, $theme_root );
}

更新日志

Versiondescription
1.5.0Introduced.

More Information

Usage


echo get_template_directory();

Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI.

In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory.

To retrieve the URI of the stylesheet directory use get_stylesheet_directory_uri() instead.

Notes

  • Uses: get_theme_root() to retrieve the absolute path to the themes directory, get_template() to retrieve the directory name of the current theme.
  • Does not output a trailing slash

相关函数

Uses

  • wp-includes/theme.php: get_theme_root()
  • wp-includes/theme.php: get_template()
  • wp-includes/theme.php: template_directory
  • 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_parent_theme_file_path()
  • wp-includes/link-template.php: get_theme_file_path()
  • wp-includes/theme.php: get_editor_stylesheets()
  • wp-includes/theme.php: validate_current_theme()
  • wp-includes/l10n.php: load_theme_textdomain()
  • wp-includes/deprecated.php: get_attachment_icon_src()
  • 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 Drew Jaynes

    Include a PHP file

    
    include( get_template_directory() . '/includes/my_file.php );
    

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

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

发布评论

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