Support » Plugin: Contextual Related Posts » Still generates code for removed thumbnails

  • Resolved Grzegorz.Janoszka

    (@grzegorzjanoszka)


    Hi,
    That is a great plugin and I have never had an issue with it until today. My site used to have (for whatever reason) 3 sizes of thumbnails – 50×50, 65×65 and 150×150. Recently I have deregistered the others sizes and removed their files. The 150×150 thumbnail files are so small anyway (I use avif+jpg) that it doesn’t matter much if I have way more slightly smaller files.
    I have saved the settings, cleared the cache, but still in the HTML code I see:

    <li><a href="LINK" target="_blank" class="page-579"><img style="max-width:150px;max-height:150px;" src="IMAGE-150x150.jpg" class="crp_thumb crp_firstcorrect" alt="Maka" title="Maka" srcset="IMAGE-150x150.jpg 150w, IMAGE-50x50.jpg 50w" sizes="(max-width: 150px) 100vw, 150px" /><span class="crp_title">Maka</span></a></li>

    How can I get rid of the 50×50 in the HTML? I don’t have such a size registered at all with WP.
    Any help appreciated, thank you in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ajay

    (@ajay)

    The plugin uses WP’s inbuilt function for the srcset: Please see this: https://github.com/WebberZone/contextual-related-posts/blob/5f7000cc1c83918636076493d346805f7c95b3a5/includes/media.php#L335

    It uses wp_get_attachment_metadata to get the meta data for the image including the sizes and it looks like the image size of 50 seems to being returned for this image.

    Is there a way you can check that?

    Hi, sorry it took so long. When I call wp_get_attachment_metadata I get:

    Array ( [width] => 1024 [height] => 679 [file] => 2014/04/mieso-paleo-smak.jpg [sizes] => Array ( [thumbnail] => Array ( [file] => mieso-paleo-smak-150×150.jpg [width] => 150 [height] => 150 [mime-type] => image/jpeg [ewww_image_optimizer] => Zmniejszono o 7.6% (692,0 B ) – Poprzednio zoptymalizowano [cw_image_optimizer] => No savings ) [medium] => Array ( [file] => mieso-paleo-smak-500×332.jpg [width] => 500 [height] => 332 [mime-type] => image/jpeg [ewww_image_optimizer] => Zmniejszono o 7.3% (3,1 kB) – Poprzednio zoptymalizowano [cw_image_optimizer] => No savings ) [large] => Array ( [file] => mieso-paleo-smak-500×332.jpg [width] => 500 [height] => 332 [mime-type] => image/jpeg [ewww_image_optimizer] => Brak zysku [cw_image_optimizer] => No savings ) [post-thumbnail] => Array ( [file] => mieso-paleo-smak-672×372.jpg [width] => 672 [height] => 372 [mime-type] => image/jpeg [ewww_image_optimizer] => Zmniejszono o 6.8% (4,5 kB) – Poprzednio zoptymalizowano [cw_image_optimizer] => No savings ) [twentyfourteen-full-width] => Array ( [file] => mieso-paleo-smak-1024×576.jpg [width] => 1024 [height] => 576 [mime-type] => image/jpeg [ewww_image_optimizer] => Zmniejszono o 6.0% (9,5 kB) – Poprzednio zoptymalizowano [cw_image_optimizer] => No savings ) [crp_thumbnail] => Array ( [file] => mieso-paleo-smak-150×150.jpg [width] => 150 [height] => 150 [mime-type] => image/jpeg [ewww_image_optimizer] => Brak zysku [cw_image_optimizer] => No savings ) [tptn_thumbnail] => Array ( [file] => mieso-paleo-smak-50×50.jpg [width] => 50 [height] => 50 [mime-type] => image/jpeg [ewww_image_optimizer] => Zmniejszono o 18.5% (390,0 B ) – Poprzednio zoptymalizowano [cw_image_optimizer] => No savings ) ) [image_meta] => Array ( [aperture] => 0 [credit] => [camera] => [caption] => [created_timestamp] => 0 [copyright] => [focal_length] => 0 [iso] => 0 [shutter_speed] => 0 [title] => [orientation] => 0 ) [ewww_image_optimizer] => Reduced by 3.6% (5,3 kB) – Poprzednio zoptymalizowano [cw_image_optimizer] => No savings )

    So shitload of rubbish parameters. I don’t have anymore the sizes 50×50, but I guess the metadata is still there.

    Any idea how I can clean up this rubbish without coding it? Is there a nice plugin for it? 🙂

    OK, in the meantime I wrote some dirty code that cleaned up all that mess from my metadata and most of the non-existing images links are gone. Some persist and I will try to get rid of them. Thank you for your support!

    Closing.

    Plugin Author Ajay

    (@ajay)

    @grzegorzjanoszka

    Sorry for the delayed response. What did you do exactly to clean up the meta data. Might be useful for my site as well.

    Hi,

    Something dirty like that:

      $args = array('post_type'=>'attachment','numberposts'=>-1);
      $attachments = get_posts($args);
      if($attachments){
        foreach($attachments as $attachment){
          $image_meta    = wp_get_attachment_metadata( $attachment->ID );
          # wywala się, jak nie ma takich rzeczy ustawionych
          unset ($image_meta['ewww_image_optimizer']);
          unset ($image_meta['cw_image_optimizer']);
          unset ($image_meta['sizes']['large']);
          unset ($image_meta['sizes']['1536x1536']);
          unset ($image_meta['sizes']['post-thumbnail']);
          unset ($image_meta['sizes']['crp_thumbnail']);
          unset ($image_meta['sizes']['tptn_thumbnail']);
          unset ($image_meta['sizes']['twentyfourteen-full-width']);
          unset ($image_meta['sizes']['thumbnail']['ewww_image_optimizer']);
          unset ($image_meta['sizes']['thumbnail']['cw_image_optimizer']);
          unset ($image_meta['sizes']['medium']['ewww_image_optimizer']);
          unset ($image_meta['sizes']['medium']['cw_image_optimizer']);
          wp_update_attachment_metadata( $attachment->ID, $image_meta);
        }
      }

    For me it worked.

    Plugin Author Ajay

    (@ajay)

    Thank you. This is pretty useful. Can be customised when I figure out my various image sizes that I need to clean. Lots of theme changs means I have a tonne of that for sure.

    • This reply was modified 1 month, 4 weeks ago by Ajay.
Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.