WPSEO_Image_Utils::get_first_usable_content_image_for_post()public staticYoast 1.0

Gets the post's first usable content image. Null if none is available.

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

Хуков нет.

Возвращает

Строку|null. The image URL.

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

$result = WPSEO_Image_Utils::get_first_usable_content_image_for_post( $post_id );
$post_id(int|null)
The post id.
По умолчанию: null

Код WPSEO_Image_Utils::get_first_usable_content_image_for_post() Yoast 22.4

public static function get_first_usable_content_image_for_post( $post_id = null ) {
	$post = get_post( $post_id );

	// We know get_post() returns the post or null.
	if ( ! $post ) {
		return null;
	}

	$image_finder = new WPSEO_Content_Images();
	$images       = $image_finder->get_images( $post->ID, $post );

	return self::get_first_image( $images );
}