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 22.3

public function generate_main_image_id() {
	if ( $this->request_helper->is_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;
	}
}