get_template_directory()
Получает системный путь до родительской темы (не дочерней). Без слэша на конце.
Используйте get_stylesheet_directory(), чтобы получить путь дочерней темы.
-
Используйте get_theme_root(), чтобы получить путь до каталога со всеми темами.
-
Используйте get_theme_root_uri(), чтобы получить УРЛ каталога со всеми темами: http://example.com/wp-content/themes
-
Используйте get_template_directory_uri(), чтобы получить УРЛ текущей темы, а не путь.
- Используйте get_template(), чтобы получить название папки текущей темы.
Вместо этой функции, раньше можно было использовать константу TEMPLATEPATH, она устарела с версии WP 6.4.
Работает на основе: get_template(), get_theme_root()
Основа для: get_parent_theme_file_path()
1 раз — 0.000028 сек (очень быстро) | 50000 раз — 0.17 сек (очень быстро) | PHP 7.1.1, WP 4.7.2
Хуки из функции
Возвращает
Строку. Путь до шаблона.
Использование
$tpl_dir = get_template_directory();
Примеры
#1 Получим путь до папки текущей темы
echo get_template_directory(); //> /home/example.com/public_html/wp-content/themes/theme_name
#2 Путь до темы через константу TEMPLATEPATH
echo TEMPLATEPATH; //> /home/example.com/public_html/wp-content/themes/theme_name
TEMPLATEPATH считается устаревшей с версии WP 6.4.
Список изменений
| С версии 1.5.0 | Введена. |
| С версии 6.4.0 | Memoizes filter execution so that it only runs once for the current theme. |
| С версии 6.4.1 | Memoization removed. |
Код get_template_directory() get template directory WP 6.8.3
function get_template_directory() {
$template = get_template();
$theme_root = get_theme_root( $template );
$template_dir = "$theme_root/$template";
/**
* Filters the active theme directory path.
*
* @since 1.5.0
*
* @param string $template_dir The path of the active theme directory.
* @param string $template Directory name of the active theme.
* @param string $theme_root Absolute path to the themes directory.
*/
return apply_filters( 'template_directory', $template_dir, $template, $theme_root );
}