WordPress как на ладони
rgbcode is looking for WordPress developers. Очень Удобный и Быстрый Хостинг для сайтов на WordPress. Пользуюсь сам и вам рекомендую!

get_template_directory()WP 1.5.0

Получает полный путь от корня сайта до текущей темы (родительской, не дочерней). Без слэша на конце.

Вместо этой функции, можно использовать константу TEMPLATEPATH (см. пример).

Чтобы получить путь дочерней темы, используйте get_stylesheet_directory().

  • Используйте get_theme_root(), чтобы получить путь до каталога со всеми темами.

  • Используйте get_theme_root_uri(), чтобы получить УРЛ каталога со всеми темами: http://example.com/wp-content/themes

  • Используйте get_template_directory_uri(), чтобы получить УРЛ текущей темы, а не путь.

  • Используйте get_template(), чтобы получить название папки текущей темы.
Работает на основе: 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();

Примеры

3

#1 Путь до темы через константу TEMPLATEPATH

echo TEMPLATEPATH;
//> /home/example.com/public_html/wp-content/themes/theme_name
0

#2 Получим путь до папки текущей темы

echo get_template_directory();
//> /home/example.com/public_html/wp-content/themes/theme_name

Заметки

  • Global. Строка. $wp_template_path Current theme template directory path.

Список изменений

С версии 1.5.0 Введена.
С версии 6.4.0 Memoizes filter execution so that it only runs once for the current theme.

Код get_template_directory() WP 6.4.1

function get_template_directory() {
	global $wp_template_path;

	if ( null === $wp_template_path ) {
		$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.
		 */
		$template_dir = apply_filters( 'template_directory', $template_dir, $template, $theme_root );

		// If there are filter callbacks, force the logic to execute on every call.
		if ( has_filter( 'template' ) || has_filter( 'theme_root' ) || has_filter( 'template_directory' ) ) {
			return $template_dir;
		}

		$wp_template_path = $template_dir;
	}

	return $wp_template_path;
}
2 комментария
    Войти