Change to default featured image (article schema #primaryimage)
-
Hi,
After Yoast 11.1.1, the code to featured image has been changed to make it either as “first image from post” or “attachment id”. However, our images hosted on external server leading to ‘image size smaller than recommended’ warning for amp pages/posts.
In order to fix the problem, we need to change the code using Yoast API. It is working except for $image_id = $data[‘image’] field which refers to ‘@id’ = “https://post-url/#primaryimage”
Need help in referencing $image_id = $data[‘image’] field to @id field in the following code:
add_filter( 'wpseo_schema_article', 'change_article_primaryimage' ); function change_article_primaryimage( $data ) { $image_url = 'https://URL-to-image.png'; $image_id = $data['image']; $schema_image = new WPSEO_Schema_Image( $image_id ); $data['image'] = $schema_image->generate_from_url( $image_url ); return $data; }
Thank you.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Change to default featured image (article schema #primaryimage)’ is closed to new replies.