# wp_guess_url()

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

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

## Сигнатура

```php
wp_guess_url(): string
```

## Описание

Удаляет ссылки на wp-admin, чтобы возвращать только URL, не находящиеся в каталоге wp-admin.

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

`string`

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

Файл: `wp-includes/functions.php:6350`

```php
function wp_guess_url() {
	if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) {
		$url = WP_SITEURL;
	} else {
		$abspath_fix         = str_replace( '\\', '/', ABSPATH );
		$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );

		// The request is for the admin.
		if ( str_contains( $_SERVER['REQUEST_URI'], 'wp-admin' ) || str_contains( $_SERVER['REQUEST_URI'], 'wp-login.php' ) ) {
			$path = preg_replace( '#/(wp-admin/?.*|wp-login\.php.*)#i', '', $_SERVER['REQUEST_URI'] );

			// The request is for a file in ABSPATH.
		} elseif ( $script_filename_dir . '/' === $abspath_fix ) {
			// Strip off any file/query params in the path.
			$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );

		} else {
			if ( str_contains( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
				// Request is hitting a file inside ABSPATH.
				$directory = str_replace( ABSPATH, '', $script_filename_dir );
				// Strip off the subdirectory, and any file/query params.
				$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] );
			} elseif ( str_contains( $abspath_fix, $script_filename_dir ) ) {
				// Request is hitting a file above ABSPATH.
				$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
				// Strip off any file/query params from the path, appending the subdirectory to the installation.
				$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory;
			} else {
				$path = $_SERVER['REQUEST_URI'];
			}
		}

		$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet.
		$url    = $schema . $_SERVER['HTTP_HOST'] . $path;
	}

	return rtrim( $url, '/' );
}
```

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

- 2.6.0 — Introduced.

## Связанные

Использует: [`is_ssl`](https://chugunov.pro/api-wordpress/functions/is_ssl/).
Используется в: [`populate_options`](https://chugunov.pro/api-wordpress/functions/populate_options/), [`wp_install`](https://chugunov.pro/api-wordpress/functions/wp_install/), [`wp_not_installed`](https://chugunov.pro/api-wordpress/functions/wp_not_installed/), [`wp_default_styles`](https://chugunov.pro/api-wordpress/functions/wp_default_styles/), [`wp_default_scripts`](https://chugunov.pro/api-wordpress/functions/wp_default_scripts/).

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