# wp_targeted_link_rel_callback()

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

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

> Устаревший элемент. Помечен устаревшим с версии 6.7.0.

## Сигнатура

```php
wp_targeted_link_rel_callback( array $matches ): string
```

## Описание

Не дублирует существующее значение «noopener», чтобы не нарушить корректность HTML.

## Параметры

- `$matches` `array` — обязательный. Одиночное совпадение.

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

`string` — rel="noopener"

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

Файл: `wp-includes/formatting.php:3357`

```php
function wp_targeted_link_rel_callback( $matches ) {
	_deprecated_function( __FUNCTION__, '6.7.0' );

	$link_html          = $matches[1];
	$original_link_html = $link_html;

	// Consider the HTML escaped if there are no unescaped quotes.
	$is_escaped = ! preg_match( '/(^|[^\\\\])[\'"]/', $link_html );
	if ( $is_escaped ) {
		// Replace only the quotes so that they are parsable by wp_kses_hair(), leave the rest as is.
		$link_html = preg_replace( '/\\\\([\'"])/', '$1', $link_html );
	}

	$atts = wp_kses_hair( $link_html, wp_allowed_protocols() );

	/**
	 * Filters the rel values that are added to links with `target` attribute.
	 *
	 * @since 5.1.0
	 *
	 * @param string $rel       The rel values.
	 * @param string $link_html The matched content of the link tag including all HTML attributes.
	 */
	$rel = apply_filters( 'wp_targeted_link_rel', 'noopener', $link_html );

	// Return early if no rel values to be added or if no actual target attribute.
	if ( ! $rel || ! isset( $atts['target'] ) ) {
		return "<a $original_link_html>";
	}

	if ( isset( $atts['rel'] ) ) {
		$all_parts = preg_split( '/\s/', "{$atts['rel']['value']} $rel", -1, PREG_SPLIT_NO_EMPTY );
		$rel       = implode( ' ', array_unique( $all_parts ) );
	}

	$atts['rel']['whole'] = 'rel="' . esc_attr( $rel ) . '"';
	$link_html            = implode( ' ', array_column( $atts, 'whole' ) );

	if ( $is_escaped ) {
		$link_html = preg_replace( '/[\'"]/', '\\\\$0', $link_html );
	}

	return "<a $link_html>";
}
```

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

- 6.7.0 — Устаревший.
- 5.6.0 — Removed 'noreferrer' relationship.
- 5.1.0 — Introduced.

## Связанные

Использует: [`wp_kses_hair`](https://chugunov.pro/api-wordpress/functions/wp_kses_hair/), [`wp_allowed_protocols`](https://chugunov.pro/api-wordpress/functions/wp_allowed_protocols/), [`esc_attr`](https://chugunov.pro/api-wordpress/functions/esc_attr/), [`_deprecated_function`](https://chugunov.pro/api-wordpress/functions/_deprecated_function/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).

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