# _block_template_add_skip_link()

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

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

## Сигнатура

```php
_block_template_add_skip_link( string $template_html ): string
```

## Описание

Если в шаблоне присутствует элемент MAIN, функция обеспечивает наличие у него атрибута id и вставляет ссылку на этот элемент MAIN перед первым элементом DIV.wp-site-blocks, который является обёрткой для всех блоков в шаблоне блока, создаваемой get_the_block_template_html().
Пример:
// Input.

...

...

// Output.

...

...Если элемент MAIN уже содержит непустое значение id, оно будет использовано вместо стандартного id ссылки для пропуска.

## Параметры

- `$template_html` `string` — обязательный. Разметка шаблона блока.

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

`string`

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

Файл: `wp-includes/block-template.php:350`

```php
function _block_template_add_skip_link( string $template_html ): string {
	// Anonymous subclass of WP_HTML_Tag_Processor to access protected bookmark spans.
	$processor = new class( $template_html ) extends WP_HTML_Tag_Processor {
		/**
		 * Inserts text before the current token.
		 *
		 * @param string $text Text to insert.
		 */
		public function insert_before( string $text ) {
			$this->set_bookmark( 'here' );
			$this->lexical_updates[] = new WP_HTML_Text_Replacement( $this->bookmarks['here']->start, 0, $text );
		}
	};

	// Find and bookmark the first DIV.wp-site-blocks.
	if (
		! $processor->next_tag(
			array(
				'tag_name'   => 'DIV',
				'class_name' => 'wp-site-blocks',
			)
		)
	) {
		return $template_html;
	}
	$processor->set_bookmark( 'skip_link_insertion_point' );

	// Ensure the MAIN element has an ID.
	if ( ! $processor->next_tag( 'MAIN' ) ) {
		return $template_html;
	}

	$skip_link_target_id = $processor->get_attribute( 'id' );
	if ( ! is_string( $skip_link_target_id ) || '' === $skip_link_target_id ) {
		$skip_link_target_id = 'wp--skip-link--target';
		$processor->set_attribute( 'id', $skip_link_target_id );
	}

	// Seek back to the bookmarked insertion point.
	$processor->seek( 'skip_link_insertion_point' );

	$skip_link = sprintf(
		'<a class="skip-link screen-reader-text" id="wp-skip-link" href="%s">%s</a>',
		esc_url( '#' . $skip_link_target_id ),
		/* translators: Hidden accessibility text. */
		esc_html__( 'Skip to content' )
	);
	$processor->insert_before( $skip_link );

	return $processor->get_updated_html();
}
```

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

- 7.0.0 — Introduced.

## Связанные

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

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