1

wp_get_attachment_image_src() is returning a wrong image url. It returns the original url instead of the cropped one. Here some example code:

    $ptId = get_post_thumbnail_id( $productId );
    print_r(wp_get_attachment_image_src( $ptId, 'thumbnail'));
    print_r(wp_get_attachment_image_src( $ptId, 'medium'));
    print_r(wp_get_attachment_image_src( $ptId, 'medium_large'));

Returns:

Array ( [0] => //localhost:3000/.../wp-content/uploads/2020/06/Mineral-Lipstick-Crème-Brûlée-scaled-1.jpg [1] => 100 [2] => 150 [3] => ) 
Array ( [0] => //localhost:3000/.../wp-content/uploads/2020/06/Mineral-Lipstick-Crème-Brûlée-scaled-1.jpg [1] => 200 [2] => 300 [3] => ) 
Array ( [0] => //localhost:3000/.../wp-content/uploads/2020/06/Mineral-Lipstick-Crème-Brûlée-scaled-1.jpg [1] => 768 [2] => 1152 [3] => )

The image sizes do exist and you can see that the function 'kind of' detects them. I've also regenerated them (both with wp-cli & the regenerate thumbnails plugin) just to be on the sure side but alas.

I don't quite get it, I've been using this function for years and suddenly I'm not getting the desired results. Any idea as to what might be going wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.