• Hi,

    I am having problem with custom sized srcset. On this page for the DANCE/ARTS/EVENTS section, I selected the WordPress default “Medium Large” size for the thumbnail images. If I check the codes, I can see the images comes with the “srcset” attribute. Please check the screenshot here.

    Then I have created a custom image size with the following code:

    add_theme_support( 'post-thumbnails' );
    add_image_size( 'medium-cropped', 768, 514, true );

    I have regenerated all the images with the Regenerate Thumbnails plugin.

    Now I have a custom size “Medium Cropped” to select in Elementor page builder. Please check the 4 thumbnails on this page. If you look at the codes, you will not see the srcset for them. Please check the second screenshot here.

    Can anyone suggest me the exact code to add in the functions.php file? I have read many tutorials but unable to find a solution.

    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It sounds like the image attachment meta data may not have been properly updated to show that your new size is available. I say this because this data is what WP uses to determine the srcset sizes listed in the img tag. It uses all sizes found in meta data.

    You can verify if my theory is correct by examining an attachment post’s meta data through the phpMyAdmin app. The data is in serialized array format, it’s a little hard to parse. I think you can make sense of it enough to see if your size is listed or not. Don’t try to correct the data manually, the format is very finicky and manual edit attempts are likely to fail.

    It’d take some custom coding to fix up the meta data if it’s found to be lacking. The alternative is to use custom code to add the appropriate srcset data through the ‘wp_calculate_image_srcset’ filter.

    I know you asked for the exact code, but I don’t have anything available to offer you, sorry. I hope this is of some help anyway.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom image size with srcset’ is closed to new replies.