Yoast\WP\SEO\Context

Meta_Tags_Context::generate_main_image_id()publicYoast 1.0

Generates the main image ID.

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

Хуков нет.

Возвращает

int|null. The main image ID.

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

$Meta_Tags_Context = new Meta_Tags_Context();
$Meta_Tags_Context->generate_main_image_id();

Код Meta_Tags_Context::generate_main_image_id() Yoast 24.0

public function generate_main_image_id() {
	if ( \wp_is_serving_rest_request() ) {
		return $this->get_main_image_id_for_rest_request();
	}

	switch ( true ) {
		case \is_singular():
			return $this->get_singular_post_image( $this->id );
		case \is_author():
		case \is_tax():
		case \is_tag():
		case \is_category():
		case \is_search():
		case \is_date():
		case \is_post_type_archive():
			if ( ! empty( $GLOBALS['wp_query']->posts ) ) {
				if ( $GLOBALS['wp_query']->get( 'fields', 'all' ) === 'ids' ) {
					return $this->get_singular_post_image( $GLOBALS['wp_query']->posts[0] );
				}

				return $this->get_singular_post_image( $GLOBALS['wp_query']->posts[0]->ID );
			}
			return null;
		default:
			return null;
	}
}