Yoast\WP\SEO\Context

Meta_Tags_Context::generate_main_image_id()publicYoast 1.0

Gets 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 20.0

public function generate_main_image_id() {
	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;
	}
}