get_stylesheet_directory_uri()
Получает URL текущей темы (дочерней если она используется или родительской). Не содержит / на конце. Учитывает SSL.
Возвращаемый УРЛ не содержит слэша (/) на конце: http://example.com/wp-content/themes/twentyten.
Результатом работы функции будет адрес начинающийся с http:// или https:// для SSL.
Эта функция аналог get_bloginfo( 'stylesheet_directory' ).
Используйте get_template_directory_uri(), чтобы получать ссылку на каталог родительской темы, даже если используется дочерняя.
Используйте get_stylesheet_directory(), когда нужно получить серверный путь до файла, а не УРЛ.
Испрользуйте get_theme_file_uri(), когда нужно получить УРЛ дочерней темы с фалбэком на УРЛ родительской темы.
Использовать get_stylesheet_uri(), чтобы получить URL файла стилей темы style.css.
Хуки из функции
Возвращает
Строку. УРЛ без слеша (/) на конце.
Использование
$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="" title="" width="" height="" />
Список изменений
| С версии 1.5.0 | Введена. |
Код get_stylesheet_directory_uri() get stylesheet directory uri WP 6.9.4
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 the 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 );
}