get_template_directory()获取当前主题所在的绝对目录路径

目录

描述

译文

检索当前主题目录

原文

Retrieves the absolute path to the directory of the current theme.

Note: Does not contain a trailing slash.

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.

get_template_directory() 描述

用法

<?php echo get_template_directory(); ?>

get_template_directory() 用法

参数

This tag has no parameters.

get_template_directory() 参数

返回值

(string

Absolute path to the directory of the current theme (without the trailing slash).

get_template_directory() 返回值

示例

Include a PHP file

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php include( get_template_directory() . '/includes/myfile.php'); ?>

get_template_directory() 示例

注意

get_template_directory() 注意

历史

添加于 版本: 1.5.0

get_template_directory() 历史

源文件

get_template_directory() 函数的代码位于 wp-includes/theme.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve current theme directory.
 *
 * @since 1.5.0
 *
 * @return string Template directory path.
 */
function get_template_directory() {
	$template = get_template();
	$theme_root = get_theme_root( $template );
	$template_dir = "$theme_root/$template";

	/**
	 * Filter 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 );
}

get_template_directory() 源文件

相关