mindkomm / timmy

Advanced image handling for Timber.
MIT License
171 stars 13 forks source link

Breaks Yoast SEO og:image #17

Open cyrillbolliger opened 5 years ago

cyrillbolliger commented 5 years ago

Issue The removal of the image sizes automatically generated when uploading an image done here makes the wordpress function image_get_intermediate_size() always return the full size image. However, if the full size image is wider or higher than 2000px, Yoast SEO rejects it as an og:image. It would therefore be great, if the image size large would not be cleared out. Or the function would at least have a filter.

Yoast SEO uses the image_get_intermediate_size() function here.

How to reproduce it Prerequisites: WordPress with Theme that uses Timmy and the Yoast SEO Plugin.

Create a post, navigate to the social section of Yoast SEO metabox and add a facebook image that is wider than 2000px. Visit the post (frontend) and inspect the source code. The meta property og:image is missing.

Then change the image to one that is smaller than 200px wide and inspect the source code again -> the meta property og:image is now here.

gchtr commented 5 years ago

Hey @cyrillbolliger

Yeah, I ran into the same issue. The issue is not only that there’s no large image size, it’s also that Yoast grabs the data from the metadata of an image, which is usually saved in the database.

With Timmy v14.0, Timmy will generate that image metadata just like it would for default WordPress images. So, to make it work, you have to:

  1. Define a large image size in your image configuration for Timmy.

    'large' => array(
        'resize'     => array( 1400 ),
        'show_in_ui' => false,
    ),
  2. Run Regenerate Thumbnails to generate the image metadata for the database.

cyrillbolliger commented 5 years ago

Hi @gchtr

Thanks for your lightning fast response. I just tested your proposed solution: It works if I regenerate the thumbnail. However if I upload a new image, it doesn't solve the problem. I still have to regenerate the thumbnail after uploading a new image in order to get it working.

Grüess uf Winti ;)

cyrillbolliger commented 5 years ago

Hi @gchtr

I found a workaround meanwhile, I'll post it here in case it helps someone else. It basically just adds the size 'large' again:

add_filter( 'intermediate_image_sizes_advanced', function ( $metadata ) {
    $metadata['large'] = array(
        'width'  => 1200, // some value that comforts facebook etc.
        'height' => 0,
        'crop'   => false,
    );

    return $metadata;
}, 11 );
gchtr commented 5 years ago

Hey @cyrillbolliger

That’s a cool little workaround! Small note for myself and others: Using the intermediate_image_sizes_advanced will use the default WordPress image resizing functionality instead of Timmy’s.

However if I upload a new image, it doesn't solve the problem. I still have to regenerate the thumbnail after uploading a new image in order to get it working.

That’s strange! I just tested it, and when I drop an image in the Media menu in the backend, the meta data is generated.

Timmy returns an empty array for intermediate_image_sizes_advanced to prevent running the default image generation of WordPress. This is for performance reasons. That filter is called in wp_generate_attachment_metadata(), which later also calls the wp_generate_attachment_metadata filter, where Timmy builds up the sizes array for the meta data.

So I have two questions for you:

  1. Where do you upload the image?
  2. Can you check whether another plugin might interfere by disabling all other plugins and try it again?

Thinking of this, I could probably use the wp_get_attachment_metadata filter to generate the sizes array for the meta data on the fly, if it’s not present 🤔.

Liebi Grüess zrugg nach Bern 🇨🇭🙌

cyrillbolliger commented 4 years ago

Gosh, I completely forgot this issue, I'm very sorry! As you edited the last response, it reappeared in my feed...

Where do you upload the image?

It works, if I upload the image as content image. However if I upload it in the social section of Yoast SEO metabox as facebook image, it doesn't. Neither if I upload it in the media library (if the Image isn't linked in the content elsewhere).

Can you check whether another plugin might interfere by disabling all other plugins and try it again?

I tried to disable all except ACF and Yoast SEO, but it didn't make a difference.