WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Wrong thumbnail size loading after theme switching (5 posts)

  1. cai_morris
    Member
    Posted 1 year ago #

    I have a local install of WordPress for development with a number of themes I am currently developing.

    There are custom thumbnail sizes set using add_image_size( 'thumb-category', 220, 180, true ); on two themes (different sizes with different names).

    The problem is this; I have theme A active, upload images and use as thumbnails. Sizes work perfectly. I activate theme B and thumbnails are the wrong size. Not a problem as the correct thumbnail size for the images do not exist so I use the regenerate thumbnail plugin to regenerate the thumbnails. Sizes then work correctly. I then switch back to theme A and the theme is using the custom size thumbnail from theme B. both image sizes do exists but it seems to always use the last custom size thumbnail generated no matter what the theme specifies.

    The only way I can get the theme to use the correct size again is to regenerate the thumbnails. Which isn't a massive problem, just a pain in the ####! I have even tried manually deleting all the thumbnail sizes except the correct size and it still tries to load the thumbnail size from the wrong theme!

    Is this the correct behaviour? i.e. using the last generated thumbnail Or should WordPress be looking for the correct size thumbnail?

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Are you sure the image is not being resized with CSS (of theme) and are not actually affected (with theme swap) but, all you need to do is clear your local browser cache to resolve a cached local image?

  3. cai_morris
    Member
    Posted 1 year ago #

    No, definitely not CSS or cache issues.

    Think i have found the problem though, I have actually got the thumbnail sizes set with the same name, so in one theme i have;

    add_image_size( 'thumb-category', 260, 160, true );

    and in the other theme i have;

    add_image_size( 'thumb-category', 300, 300, true );

    I havn't had time to do any proper testing but i'm guessing it has something to with defining sizes with the same name.

  4. michael.mariart
    Member
    Posted 1 year ago #

    That's 100% the issue. You can't expect two definitions of the same name with different sizes to give you the same result. For this you will have to either put up with it, or use different names for all image sizes.

    I do have one sugestion though. Seeing as how you're doing theme development it would make a lot more sense (to me anyway) to have a single WP installation set up for each theme that you're doing. That would let you set up as many theme development areas as you like, you don't have to worry about any sort of overlap like this, and it means that you will be able to know exactly which one you're working on at any timeregardless of what the sites settings are. The less possible confusion, the better. :)

  5. cai_morris
    Member
    Posted 1 year ago #

    Yeh that does kind of make sense, although if a theme specifies an image size in its functions.php I'd expect it to use the correct size, even if a previous theme had defined a different size with the same name, surely wordpress should just see the custom size in the functions.php and see an image of the correct size and use that!? I'm assuming wordpress stores the image data with the size name in the database and that's why it's pulling in the wrong image.

    I didn't originally realise the sizes had been added with the same names as one theme is fairly old and the other I have recently started. I guess I just need to use less generic names in the future.

    I do actually have a number of local wordpress installs (4 I believe) and a multisite network with a few sites that I use for different themes, I was actually just working through some older themes I hadn't touched in a while.

Topic Closed

This topic has been closed to new replies.

About this Topic