Yoast\WP\SEO\Builders

Indexable_Post_Builder::find_alternative_image()protectedYoast 1.0

Finds an alternative image for the social image.

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

Хуков нет.

Возвращает

Массив|true|false. False when not found, array with data when found.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->find_alternative_image( $indexable );
$indexable(Indexable) (обязательный)
The indexable.

Код Indexable_Post_Builder::find_alternative_image() Yoast 22.4

protected function find_alternative_image( Indexable $indexable ) {
	if (
		$indexable->object_sub_type === 'attachment'
		&& $this->image->is_valid_attachment( $indexable->object_id )
	) {
		return [
			'image_id' => $indexable->object_id,
			'source'   => 'attachment-image',
		];
	}

	$featured_image_id = $this->image->get_featured_image_id( $indexable->object_id );
	if ( $featured_image_id ) {
		return [
			'image_id' => $featured_image_id,
			'source'   => 'featured-image',
		];
	}

	$gallery_image = $this->image->get_gallery_image( $indexable->object_id );
	if ( $gallery_image ) {
		return [
			'image'  => $gallery_image,
			'source' => 'gallery-image',
		];
	}

	$content_image = $this->image->get_post_content_image( $indexable->object_id );
	if ( $content_image ) {
		return [
			'image'  => $content_image,
			'source' => 'first-content-image',
		];
	}

	return false;
}