Hi @shrewdies,
Wow, you’re running Native AMP!
Yes, this looks to be a bug. Thanks for letting me know about it.
I also saw that, where the schema.org data doesn’t have an image value for attachment pages:
https://www.goutpal.com/11607/gout-in-shoulder/shoulder-in-gout-mri-media/

It looks like you’re right that amp_get_post_image_metadata()
isn’t getting the data of an image if the page is an attachment page.
I’ll request a GitHub issue for this. In the meantime, placing this in your theme should add the image. It worked for me locally:
/**
* Add data for an image when the page is an attachment page.
*
* On attachment pages, like pages for an image, there wasn't a schema.org value for 'image.'
* So this adds it via a filter.
*
* @param array $metadata The schema.org metadata.
* @param WP_Post $post The post to which it applies.
* @return array $metadata The filtered schema.org metadata.
*/
add_filter( 'amp_post_template_metadata', function( $metadata, $post ) {
if ( empty( $metadata['image'] ) && ( 'attachment' === $post->post_type ) ) {
$post_image_src = wp_get_attachment_image_src( $post->ID, 'full' );
if ( is_array( $post_image_src ) ) {
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => $post_image_src[0],
'width' => $post_image_src[1],
'height' => $post_image_src[2],
);
}
}
return $metadata;
}, 10, 2 );
GitHub Issue
Hi @shrewdies,
Here’s the GitHub issue for this, so you know when a fix is deployed:
https://github.com/Automattic/amp-wp/issues/1157
Thank you very much for your fast response @ryankienstra
I’ve since noticed that this also applies to pdf attachments. But I’m not familiar with GitHub. So I wonder if this should be commented there, or raised as a new issue?
Thanks again.
Hi @shrewdies,
Thanks for your great review. It’s exciting to see your site running Native AMP.
Yes, I also see that the issue exists for .pdf
attachments as well. And it looks like the Google Structured Data Testing Tool accepts .pdf
documents in the ImageObject
.
Feel free to open a GitHub issue for that:
https://github.com/Automattic/amp-wp/issues/new
Also, simply commenting on this GitHub issue and linking to this support topic would be fine:
https://github.com/Automattic/amp-wp/issues/1157