When validating my wordpress posts using Google's Structured Data Testing Tool, I get the following error:
"Image: missing and required"
I have the official wordpress AMP plugin installed that generated the AMP pages for me. The problem is that it doesn't popular the "image" attribute for BlogPosting
.
In the plugin there is a code that I think should generate it, but it's not running anywhere:
private function get_post_image_metadata() {
$post_image_meta = null;
$post_image_id = false;
if ( has_post_thumbnail( $this->ID ) ) {
$post_image_id = get_post_thumbnail_id( $this->ID );
} else {
$attached_image_ids = get_posts( array(
'post_parent' => $this->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => 1,
'orderby' => 'menu_order',
'order' => 'ASC',
'fields' => 'ids',
'suppress_filters' => false,
) );
if ( ! empty( $attached_image_ids ) ) {
$post_image_id = array_shift( $attached_image_ids );
}
}
if ( ! $post_image_id ) {
return false;
}
$post_image_src = wp_get_attachment_image_src( $post_image_id, 'full' );
if ( is_array( $post_image_src ) ) {
$post_image_meta = array(
'@type' => 'ImageObject',
'url' => $post_image_src[0],
'width' => $post_image_src[1],
'height' => $post_image_src[2],
);
}
return $post_image_meta;
}
How can I populate the image tag for each post using this AMP Wordpress plugin? I want the page to pass the Sturctured Data Testing Tool, so he can pass the AMP validation as well.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire