get_template_directory()
Получает полный путь от корня сайта до текущей темы (родительской, не дочерней). Не содержит слэш на конце.
Вместо этой функции, можно использовать константу TEMPLATEPATH
(см. пример).
Чтобы получить путь дочерней темы, используйте get_stylesheet_directory().
- Используйте get_theme_root(), чтобы получить путь до каталога со всеми темами.
- Используйте get_theme_root_uri(), чтобы получить УРЛ каталога со всеми темами:
http://example.com/wp-content/themes
- Используйте get_template_directory_uri(), чтобы получить УРЛ текущей темы, а не путь.
- Используйте get_template(), чтобы получить название папки текущей темы.
Является основой для: get_parent_theme_file_path()
Работает на основе: get_template()
, get_theme_root()
Хуки из функции
template_directory
Возвращает
Строку. Путь до шаблона.
Использование
$tpl_dir = get_template_directory();
Примеры
#1 Получим путь до папки текущей темы
echo get_template_directory();
//> /home/site.ru/public_html/wp-content/themes/theme_name
#2 Путь до темы через константу TEMPLATEPATH
echo TEMPLATEPATH;
//> /home/site.ru/public_html/wp-content/themes/theme_name
Код get template directory: wp-includes/theme.php
WP 5.3
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 );
}
источник: https://wp-kama.ru/function/get_template_directory