# get_adjacent_image_link()

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

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

## Сигнатура

```php
get_adjacent_image_link( bool $prev = true, string|int[] $size = 'thumbnail', bool $text = false ): string
```

## Описание

Получает текущий объект вложения из глобальной переменной $post.

## Параметры

- `$prev` `bool` — необязательный, по умолчанию `true`. Отображать ли ссылку на следующее (false) или предыдущее (true).
- `$size` `string|int[]` — необязательный, по умолчанию `'thumbnail'`. Размер изображения. Принимает имя любого зарегистрированного размера изображения или массив значений ширины и высоты в пикселях (именно в таком порядке). Значение по умолчанию 'thumbnail'.
- `$text` `bool` — необязательный, по умолчанию `false`. Текст ссылки.

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

`string`

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

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

```php
function get_adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
	$post        = get_post();
	$attachments = array_values(
		get_children(
			array(
				'post_parent'    => $post->post_parent,
				'post_status'    => 'inherit',
				'post_type'      => 'attachment',
				'post_mime_type' => 'image',
				'order'          => 'ASC',
				'orderby'        => 'menu_order ID',
			)
		)
	);

	foreach ( $attachments as $k => $attachment ) {
		if ( (int) $attachment->ID === (int) $post->ID ) {
			break;
		}
	}

	$output        = '';
	$attachment_id = 0;

	if ( $attachments ) {
		$k = $prev ? $k - 1 : $k + 1;

		if ( isset( $attachments[ $k ] ) ) {
			$attachment_id = $attachments[ $k ]->ID;
			$attr          = array( 'alt' => get_the_title( $attachment_id ) );
			$output        = wp_get_attachment_link( $attachment_id, $size, true, false, $text, $attr );
		}
	}

	$adjacent = $prev ? 'previous' : 'next';

	/**
	 * Filters the adjacent image link.
	 *
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
	 * either 'next', or 'previous'.
	 *
	 * Possible hook names include:
	 *
	 *  - `next_image_link`
	 *  - `previous_image_link`
	 *
	 * @since 3.5.0
	 *
	 * @param string $output        Adjacent image HTML markup.
	 * @param int    $attachment_id Attachment ID
	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
	 *                              an array of width and height values in pixels (in that order).
	 * @param string $text          Link text.
	 */
	return apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
}
```

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

- 5.8.0 — Introduced.

## Связанные

Использует: [`get_children`](https://chugunov.pro/api-wordpress/functions/get_children/), [`wp_get_attachment_link`](https://chugunov.pro/api-wordpress/functions/wp_get_attachment_link/), [`get_the_title`](https://chugunov.pro/api-wordpress/functions/get_the_title/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: [`get_next_image_link`](https://chugunov.pro/api-wordpress/functions/get_next_image_link/), [`get_previous_image_link`](https://chugunov.pro/api-wordpress/functions/get_previous_image_link/), [`adjacent_image_link`](https://chugunov.pro/api-wordpress/functions/adjacent_image_link/).

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