get_stylesheet_directory()
Получает абсолютный путь до папки дочерней темы или родительской (если дочерняя тема НЕ используется). Не содержит закрывающего слэша /
.
Эта функция указывает на папку, где находится текущий файл стилей темы.
Пример: если сейчас активирована родительская тема, то мы молучим путь до нее, а если дочерняя то путь до дочерней темы.
Так, эту функцию можно использовать в родительской теме, чтобы получить путь до дочерней темы, когда она будет активирована.
Используйте get_template_directory(), когда нужно получить путь до родительской темы из дочерней.
Используйте get_stylesheet_directory_uri(), когда нужно получить URL, а не путь.
Хуки из функции
Возвращает
Строку
. Абсолютный путь до каталога темы: /home/example.com/www/wp-content/themes/theme
.
Использование
get_stylesheet_directory();
Примеры
#1 Подключим файл myfile.php из папки текущей темы:
Пример, показывает, как использовать функцию. Используетм такой код в родительской теме, чтобы сделать поддержку дочерней темы:
require_once get_stylesheet_directory(). '/includes/myfile.php';
#2 Демонстрация работы функции:
echo get_stylesheet_directory(); // вернет: /home/k/kama/example.com/public_html/wp-content/themes/themename
Список изменений
С версии 1.5.0 | Введена. |
С версии 6.4.0 | Memoizes filter execution so that it only runs once for the current theme. |
С версии 6.4.2 | Memoization removed. |
Код get_stylesheet_directory() get stylesheet directory WP 6.7.1
function get_stylesheet_directory() { $stylesheet = get_stylesheet(); $theme_root = get_theme_root( $stylesheet ); $stylesheet_dir = "$theme_root/$stylesheet"; /** * Filters the stylesheet directory path for the active theme. * * @since 1.5.0 * * @param string $stylesheet_dir Absolute path to the active theme. * @param string $stylesheet Directory name of the active theme. * @param string $theme_root Absolute path to themes directory. */ return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root ); }