• Resolved Ana A

    (@ihealthcareanalyst)


    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)
  • (I am not the plugin maintainer, just a simple dev from the internets ?? )
    External images need to be resized and saved locally to match the minimum width/length required.
    Unfortunately I couldn’t find the filter you specified inside the free version, maybe you’re using the premium, an older or a customized version.
    It would be easier to try to fix your problem via ftp (i require access just to the wordpress-seo plugin and one article page to test on). I am unavailable now.

    • This reply was modified 5 years, 4 months ago by thundorstorm.

    try

    $context = new WPSEO_Schema_Context(); 
    $data['@id'] = $context->canonical . WPSEO_Schema_IDs::PRIMARY_IMAGE_HASH;

    it may work

    Thread Starter Ana A

    (@ihealthcareanalyst)

    Thank you @thundorstorm. Let me try and get back to you.

    Hi @ihealthcareanalyst,

    We see it has been a little over a week. We wanted to follow-up and see if you were able to resolve the issue. We ask as if the issue has been resolved, we can close this topic.

    Plugin Support devnihil

    (@devnihil)

    We are going ahead and marking this issue as resolved due to inactivity. If you require any further assistance please create a new issue.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change to default featured image (article schema #primaryimage)’ is closed to new replies.