Yoast\WP\SEO\Helpers\Schema
Image_Helper::generate_from_attachment_meta
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_meta( $schema_id, $attachment_meta, $caption, $add_hash );
- $schema_id(строка) (обязательный)
- The
@idto use for the returned image. - $attachment_meta(массив) (обязательный)
- The attachment metadata.
- $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_meta() Image Helper::generate from attachment meta Yoast 27.6
public function generate_from_attachment_meta( $schema_id, $attachment_meta, $caption = '', $add_hash = false ) {
$data = $this->generate_object();
$id_suffix = ( $add_hash ) ? \md5( $attachment_meta['url'] ) : '';
$data['@id'] = $schema_id . $id_suffix;
$data['url'] = $attachment_meta['url'];
$data['contentUrl'] = $data['url'];
$data['width'] = $attachment_meta['width'];
$data['height'] = $attachment_meta['height'];
if ( ! empty( $caption ) ) {
$data['caption'] = $this->html->smart_strip_tags( $caption );
}
return $data;
}