0

I have wordpress with multisite, so it will be pc and mobile version. On my pc version, i can use wp_get_attachment_image_src(get_post_thumbnail_id($id), array('210','210'))

But on my mobile version, it doesn't work. I can get the image but the size didn't change.

Do anyone know why? Do i need to set something else? Thank you

  • Perhaps this is related (get post thumbnail url with multisite): wordpress.stackexchange.com/a/192398/38771 – P-S Apr 5 '18 at 8:03
  • @P-S i already can show the image, but the size still don't change.. do we need to set something before use the code? – beginnerprogrammer Apr 5 '18 at 8:06
  • What happens if you replace your custom size array with a standard Wordpress one like 'medium' or 'thumbnail'? Is the image in the right size? (simply debugging here) – P-S Apr 5 '18 at 8:43
0

1- In functions.php

add_theme_support( 'post-thumbnails' );
add_image_size('my-custom-thumb', 210, 210, true);

2- Note (https://codex.wordpress.org/Function_Reference/set_post_thumbnail_size)

This function will not resize your existing featured images. To regenerate existing images in the new size, use the Regenerate Thumbnails (http://wordpress.org/plugins/regenerate-thumbnails/) plugin.

3- Then

wp_get_attachment_image_src(get_post_thumbnail_id($id), 'my-custom-thumb')

If that doesn't work, then I would probably triple check if there is an image uploaded for that $id on the mobile version (just check manually from the backend), and if its custom-sized version exists in the directory you set for uploads. You can manually check for the thumbnail in the database too (check this: https://stackoverflow.com/a/28643825/1427624), and then your custom-sized thumbnail should be in the same directory of the url value in the guid column.

If all of this checks out, and it's still not working, but you can successfully get an image with the size parameter "medium" or "thumbnail", then maybe you would use an automatic cropper either on the server side or the frontend side to dynamically crop that image to your custom size (a.k.a. the "out of good solutions" solution).

  • i only can get the url, all the size parameter doesn't work at all.. any idea? – beginnerprogrammer Apr 5 '18 at 9:37
  • That same url, go to the folder that contains this image in your system, does it have the 210x210 image there or not? Would be the same name of the image but with 210x210 at the end. – P-S Apr 7 '18 at 7:17

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.