OK, so generate_featured_page_header_area() is adding the featured image on that template. It is then using the_post_thumbnail(). So you can use this code to inject the data-hero attribute into the featured image on singular templates:
add_filter( 'post_thumbnail_html', function ( $html, $post_id ) {
if ( is_singular() && get_queried_object_id() === $post_id ) {
$html = preg_replace( '/(?<=<img\s)/', 'data-hero ', $html );
}
return $html;
}, 10, 2 );
Great, that seems to work. You can check out an example here https://www.ryansmithphotography.com/blog/2021/02/14/rainy-wedding-day-at-the-grand-dunes-resort-golf-club-in-myrtle-beach/. I can see why this is going to be difficult to implement for everyone if every theme implements featured images differently.
Yeah, that’s why we need to implement that issue to fix the logic for automatically picking images for prerendering. It should be such that once that is resolved, you can remove all this custom code and it should behave the same.
@rsmith4321
Your scores are really good now. I also use GeneratePress in one of the websites. Can you please quickly summarize what all changes I need to do – and which files – for the changes to take effect?
The latest amp plugin takes care of it automatically no changes needed.