get_theme_root_uri()WP 1.5.0

Получает УРЛ каталога с темами. УРЛ не имеет заканчивающего слэша.

Эта функция является оберткой для конструкции content_url( 'themes' ).

Использует глобальную переменную $wp_theme_directories.

Чтобы получить абсолютный путь до папки с темами используйте get_theme_root()

Работает на основе: content_url()
1 раз — 0.00004 сек (очень быстро) | 50000 раз — 2.11 сек (быстро)
Хуки из функции

Возвращает

Строку. УРЛ на директорию шаблонов.

Использование

get_theme_root_uri( $stylesheet_or_template, $theme_root );
$stylesheet_or_template(строка)
Название темы, УРЛ которой нужно получить.
По умолчанию: ''
$theme_root(строка)

Путь до корня темы, который будет использован в определении URL. Заменяет вызов функции get_raw_theme_root().

Примеры значений:

'/themes'

$theme_root = get_option( 'stylesheet_root' );

$theme_root = get_option( 'template_root' );

$theme_roots = get_theme_roots();
$theme_root = $theme_roots[ $stylesheet_or_template ];

По умолчанию: ''

Примеры

0

#1 Пример работы функции

<?php
$themes_directory = get_theme_root_uri();
echo $themes_directory;

// вернет:
// http://www.wp-kama.ru/wp-content/themes

Заметки

  • Global. Массив. $wp_theme_directories

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

С версии 1.5.0 Введена.

Код get_theme_root_uri() WP 6.5.2

function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) {
	global $wp_theme_directories;

	if ( $stylesheet_or_template && ! $theme_root ) {
		$theme_root = get_raw_theme_root( $stylesheet_or_template );
	}

	if ( $stylesheet_or_template && $theme_root ) {
		if ( in_array( $theme_root, (array) $wp_theme_directories, true ) ) {
			// Absolute path. Make an educated guess. YMMV -- but note the filter below.
			if ( str_starts_with( $theme_root, WP_CONTENT_DIR ) ) {
				$theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) );
			} elseif ( str_starts_with( $theme_root, ABSPATH ) ) {
				$theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) );
			} elseif ( str_starts_with( $theme_root, WP_PLUGIN_DIR ) || str_starts_with( $theme_root, WPMU_PLUGIN_DIR ) ) {
				$theme_root_uri = plugins_url( basename( $theme_root ), $theme_root );
			} else {
				$theme_root_uri = $theme_root;
			}
		} else {
			$theme_root_uri = content_url( $theme_root );
		}
	} else {
		$theme_root_uri = content_url( 'themes' );
	}

	/**
	 * Filters the URI for themes directory.
	 *
	 * @since 1.5.0
	 *
	 * @param string $theme_root_uri         The URI for themes directory.
	 * @param string $siteurl                WordPress web address which is set in General Options.
	 * @param string $stylesheet_or_template The stylesheet or template name of the theme.
	 */
	return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template );
}