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().
Хуки из функции
Возвращает
Строку
. УРЛ без слеша (/) на конце.
Использование
$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.5.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 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 ); }