get_stylesheet_directory_uri()
Отримує URL поточної теми (дочірня якщо вона використовується або батьківської). Не містить / на кінці. Враховує SSL.
УРЛ, що повертається, не містить слеша ( / ) на кінці: http://example.com/wp-content/themes/twentyten.
Результатом роботи функції буде адреса, що починається з http:// або https:// для SSL.
Використовуйте get_template_directory_uri() , щоб отримувати посилання на каталог батьківської теми, навіть якщо використовується дочірня.
Ця функція аналог get_bloginfo( 'stylesheet_directory' ).
Щоб отримати URL стилів теми: файл style.css можна використовувати спеціальну функцію get_stylesheet_uri() .
Якщо потрібно підключити в PHP файл, то вам потрібне не посилання, а шлях, використовуйте для цього функцію: get_stylesheet_directory() .
(дуже повільно) | 50000 разів – 4.39 сек
(швидко) |
PHP 7.4.25, WP 5.9.3
Хуки з функції
Повертає
Строку. УРЛ без слєша (/) на кінці.
Використання
$theme_url = get_stylesheet_directory_uri();
Приклади
#1 Завантаження css-стилів:
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
function my_scripts_method() {
wp_enqueue_script(
'custom_script',
get_stylesheet_directory_uri() . '/js/custom_script.js',
['jquery']
);
}
#2 Демонстрація роботи функції. Виведемо на екран картинку з нашої теми:
<img src="<?php echo get_stylesheet_directory_uri() ?>/images/aternus.png" alt="get_stylesheet_directory_uri() – Отримує URL поточної теми (дочірньої якщо вона використовується або батьківської)." title="" width="" height="" />
список змін
| З версії 1.5.0 | Введено. |
Код get_stylesheet_directory_uri() get stylesheet directory uri WP 6.0.2
function get_stylesheet_directory_uri() {
$stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );
$ theme_root_uri = get_theme_root_uri ($ stylesheet);
$stylesheet_dir_uri = "$theme_root_uri/$stylesheet";
/**
* Filters stylesheet directory URI.
*
* @ Since 1.5.0
*
* @param string $stylesheet_dir_uri Stylesheet directory URI.
* @param string $stylesheet Name of the activated theme's directory.
* @param string $theme_root_uri Themes root URI.
*/
return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri );
}