# _wp_get_attachment_relative_path()

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

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

## Сигнатура

```php
_wp_get_attachment_relative_path( string $file ): string
```

## Описание

Возвращает путь к вложению относительно каталога загрузок.

## Параметры

- `$file` `string` — обязательный. Имя файла вложения.

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

`string`

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

Файл: `wp-includes/media.php:1244`

```php
function _wp_get_attachment_relative_path( $file ) {
	$dirname = dirname( $file );

	if ( '.' === $dirname ) {
		return '';
	}

	if ( str_contains( $dirname, 'wp-content/uploads' ) ) {
		// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
		$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
		$dirname = ltrim( $dirname, '/' );
	}

	return $dirname;
}
```

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

- 4.4.1 — Introduced.

## Связанные

Используется в: [`wp_image_file_matches_image_meta`](https://chugunov.pro/api-wordpress/functions/wp_image_file_matches_image_meta/), [`wp_calculate_image_srcset`](https://chugunov.pro/api-wordpress/functions/wp_calculate_image_srcset/), [`wp_get_attachment_url`](https://chugunov.pro/api-wordpress/functions/wp_get_attachment_url/).

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