Yoast\WP\SEO\Helpers

Image_Helper::get_best_attachment_variation()publicYoast 1.0

Retrieves the best attachment variation for the given attachment.

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

Хуков нет.

Возвращает

true|false|Строку. The attachment url or false when no variations found.

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

$Image_Helper = new Image_Helper();
$Image_Helper->get_best_attachment_variation( $attachment_id );
$attachment_id(int) (обязательный)
The attachment id.

Код Image_Helper::get_best_attachment_variation() Yoast 22.4

public function get_best_attachment_variation( $attachment_id ) {
	$variations = WPSEO_Image_Utils::get_variations( $attachment_id );
	$variations = WPSEO_Image_Utils::filter_usable_file_size( $variations );

	// If we are left without variations, there is no valid variation for this attachment.
	if ( empty( $variations ) ) {
		return false;
	}

	// The variations are ordered so the first variations is by definition the best one.
	return \reset( $variations );
}