Yoast\WP\SEO\Context
Meta_Tags_Context::generate_main_image_id
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() Meta Tags Context::generate main image id Yoast 26.5
public function generate_main_image_id() {
if ( \wp_is_serving_rest_request() ) {
return $this->get_main_image_id_for_rest_request();
}
$image_id = null;
switch ( true ) {
case \is_singular():
$image_id = $this->get_singular_post_image( $this->id );
break;
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' ) {
$image_id = $this->get_singular_post_image( $GLOBALS['wp_query']->posts[0] );
break;
}
$image_id = $this->get_singular_post_image( $GLOBALS['wp_query']->posts[0]->ID );
}
break;
}
/**
* Filter: 'wpseo_schema_main_image_id' - Allow changing the main image ID.
*
* @param int|array $image_id The image ID.
*/
return \apply_filters( 'wpseo_schema_main_image_id', $image_id );
}