Yoast\WP\SEO\Helpers\Schema
Image_Helper::generate_from_attachment_id()
Retrieve data about an image from the database and use it to generate a Schema object.
Метод класса: Image_Helper{}
Хуков нет.
Возвращает
Массив
. Schema ImageObject array.
Использование
$Image_Helper = new Image_Helper(); $Image_Helper->generate_from_attachment_id( $schema_id, $attachment_id, $caption, $add_hash );
- $schema_id(строка) (обязательный)
- The @id to use for the returned image.
- $attachment_id(int) (обязательный)
- The attachment to retrieve data from.
- $caption(строка)
- The caption string, if there is one.
По умолчанию: '' - $add_hash(true|false)
- Whether a hash will be added as a suffix in the @id.
По умолчанию: false
Код Image_Helper::generate_from_attachment_id() Image Helper::generate from attachment id Yoast 22.4
public function generate_from_attachment_id( $schema_id, $attachment_id, $caption = '', $add_hash = false ) { $data = $this->generate_object(); $url = $this->image->get_attachment_image_url( $attachment_id, 'full' ); $id_suffix = ( $add_hash ) ? \md5( $url ) : ''; $data['@id'] = $schema_id . $id_suffix; $data['url'] = $url; $data['contentUrl'] = $url; $data = $this->add_image_size( $data, $attachment_id ); $data = $this->add_caption( $data, $attachment_id, $caption ); return $data; }