Yoast\WP\SEO\Generators\Schema

HowTo::add_how_to()protectedYoast 1.0

Generates the HowTo schema for a block.

Метод класса: HowTo{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->add_how_to( $graph, $block, $index );
$graph(массив) (обязательный) (передается по ссылке — &)
Our Schema data.
$block(массив) (обязательный)
The How-To block content.
$index(int) (обязательный)
The index of the current block.

Код HowTo::add_how_to() Yoast 22.4

protected function add_how_to( &$graph, $block, $index ) {
	$data = [
		'@type'            => 'HowTo',
		'@id'              => $this->context->canonical . '#howto-' . ( $index + 1 ),
		'name'             => $this->helpers->schema->html->smart_strip_tags( $this->helpers->post->get_post_title_with_fallback( $this->context->id ) ),
		'mainEntityOfPage' => [ '@id' => $this->context->main_schema_id ],
		'description'      => '',
	];

	if ( $this->context->has_article ) {
		$data['mainEntityOfPage'] = [ '@id' => $this->context->main_schema_id . Schema_IDs::ARTICLE_HASH ];
	}

	if ( isset( $block['attrs']['jsonDescription'] ) ) {
		$data['description'] = $this->helpers->schema->html->sanitize( $block['attrs']['jsonDescription'] );
	}

	$this->add_duration( $data, $block['attrs'] );

	if ( isset( $block['attrs']['steps'] ) ) {
		$this->add_steps( $data, $block['attrs']['steps'] );
	}

	$data = $this->helpers->schema->language->add_piece_language( $data );

	$graph[] = $data;
}