# set_url_scheme()

URL: https://chugunov.pro/api-wordpress/functions/set_url_scheme/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 3.4.0.

## Сигнатура

```php
set_url_scheme( string $url, string|null $scheme = null ): string
```

## Описание

Задаёт схему для URL.

## Параметры

- `$url` `string` — обязательный. Абсолютный URL, включающий схему
- `$scheme` `string|null` — необязательный, по умолчанию `null`. Схема, задаваемая для $url. В настоящее время 'http', 'https', 'login', 'login_post', 'admin', 'relative', 'rest', 'rpc' или null.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/link-template.php:3930`

```php
function set_url_scheme( $url, $scheme = null ) {
	$orig_scheme = $scheme;

	if ( ! $scheme ) {
		$scheme = is_ssl() ? 'https' : 'http';
	} elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) {
		$scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
	} elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) {
		$scheme = is_ssl() ? 'https' : 'http';
	}

	$url = trim( $url );
	if ( str_starts_with( $url, '//' ) ) {
		$url = 'http:' . $url;
	}

	if ( 'relative' === $scheme ) {
		$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
		if ( '' !== $url && '/' === $url[0] ) {
			$url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" );
		}
	} else {
		$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
	}

	/**
	 * Filters the resulting URL after setting the scheme.
	 *
	 * @since 3.4.0
	 *
	 * @param string      $url         The complete URL including scheme and path.
	 * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
	 * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
	 *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
	 */
	return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
}
```

## История изменений

- 4.4.0 — The 'rest' scheme was added.
- 3.4.0 — Introduced.

## Связанные

Использует: [`is_ssl`](https://chugunov.pro/api-wordpress/functions/is_ssl/), [`force_ssl_admin`](https://chugunov.pro/api-wordpress/functions/force_ssl_admin/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_REST_Pattern_Directory_Controller::get_items`, [`get_self_link`](https://chugunov.pro/api-wordpress/functions/get_self_link/), [`wp_check_php_version`](https://chugunov.pro/api-wordpress/functions/wp_check_php_version/), `WP_Customize_Manager::handle_load_themes_request`, `WP_Community_Events::get_events`, [`get_header_video_url`](https://chugunov.pro/api-wordpress/functions/get_header_video_url/), [`get_rest_url`](https://chugunov.pro/api-wordpress/functions/get_rest_url/), [`wp_calculate_image_srcset`](https://chugunov.pro/api-wordpress/functions/wp_calculate_image_srcset/), [`get_preview_post_link`](https://chugunov.pro/api-wordpress/functions/get_preview_post_link/), [`wp_admin_canonical_url`](https://chugunov.pro/api-wordpress/functions/wp_admin_canonical_url/), [`translations_api`](https://chugunov.pro/api-wordpress/functions/translations_api/), [`themes_api`](https://chugunov.pro/api-wordpress/functions/themes_api/), `WP_List_Table::pagination`, `WP_List_Table::print_column_headers`, [`get_core_checksums`](https://chugunov.pro/api-wordpress/functions/get_core_checksums/), [`wp_check_browser_version`](https://chugunov.pro/api-wordpress/functions/wp_check_browser_version/), [`plugins_api`](https://chugunov.pro/api-wordpress/functions/plugins_api/), [`add_menu_page`](https://chugunov.pro/api-wordpress/functions/add_menu_page/), [`edit_form_image_editor`](https://chugunov.pro/api-wordpress/functions/edit_form_image_editor/), [`wp_ajax_query_themes`](https://chugunov.pro/api-wordpress/functions/wp_ajax_query_themes/), [`get_home_path`](https://chugunov.pro/api-wordpress/functions/get_home_path/), [`wp_get_popular_importers`](https://chugunov.pro/api-wordpress/functions/wp_get_popular_importers/), [`wp_credits`](https://chugunov.pro/api-wordpress/functions/wp_credits/), `Custom_Image_Header::show_header_selector`, `Custom_Background::admin_page`, [`_custom_background_cb`](https://chugunov.pro/api-wordpress/functions/_custom_background_cb/), [`get_header_image`](https://chugunov.pro/api-wordpress/functions/get_header_image/), [`auth_redirect`](https://chugunov.pro/api-wordpress/functions/auth_redirect/), [`url_is_accessable_via_ssl`](https://chugunov.pro/api-wordpress/functions/url_is_accessable_via_ssl/), [`content_url`](https://chugunov.pro/api-wordpress/functions/content_url/), [`plugins_url`](https://chugunov.pro/api-wordpress/functions/plugins_url/), [`network_site_url`](https://chugunov.pro/api-wordpress/functions/network_site_url/), [`network_home_url`](https://chugunov.pro/api-wordpress/functions/network_home_url/), [`get_home_url`](https://chugunov.pro/api-wordpress/functions/get_home_url/), [`get_site_url`](https://chugunov.pro/api-wordpress/functions/get_site_url/), [`wp_version_check`](https://chugunov.pro/api-wordpress/functions/wp_version_check/), [`wp_update_plugins`](https://chugunov.pro/api-wordpress/functions/wp_update_plugins/), [`wp_update_themes`](https://chugunov.pro/api-wordpress/functions/wp_update_themes/), [`_wp_menu_item_classes_by_context`](https://chugunov.pro/api-wordpress/functions/_wp_menu_item_classes_by_context/), [`wp_video_shortcode`](https://chugunov.pro/api-wordpress/functions/wp_video_shortcode/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/set_url_scheme/
