Post-thumbnails功能未正常注册,缩略图硬裁剪失效求助
Let’s break down the most common checks and fixes to get your hard crop working correctly—this is a super frequent issue with WordPress custom image sizes, so you’re in good company!
Double-check your
add_image_sizecode
Make sure you’re passingtrueas the fourth parameter (wait, correction: it’s the third parameter for hard crop—syntax isadd_image_size( $name, $width, $height, $crop );). If you accidentally usedfalseor omitted the parameter entirely, it’ll default to soft crop. If you want to control crop positioning, you can use an array likearray( 'center', 'top' )(still counts as hard crop). Example of correct hard crop code:add_image_size( 'custom-post-thumb', 400, 300, true );Verify the order of theme support and image size registration
Youradd_theme_support( 'post-thumbnails' )needs to run before you register your custom image sizes. If you register the size first, WordPress might not apply the crop setting properly. Move the post thumbnail support line to the top of yourfunctions.phpfile, before anyadd_image_sizecalls.Regenerate existing thumbnails
WordPress doesn’t automatically re-crop images you uploaded before adding the custom size. You’ll need to regenerate them to apply the new hard crop. You can use a plugin like Regenerate Thumbnails, or run this WP CLI command if you have server access:wp media regenerate --image_size=custom-post-thumb(Replace
custom-post-thumbwith your actual custom size name.)Rule out theme/plugin conflicts
Some themes have built-in image size overrides, and image optimization plugins (those that compress or resize images) might override your crop settings. Try switching to a default WordPress theme (like Twenty Twenty-Four) and disabling all non-essential plugins, then test if the hard crop works. If it does, re-enable them one by one to find the culprit.Confirm you’re calling the correct image size
It sounds obvious, but make sure your template code is actually using the custom size you created. For example, if you registeredcustom-post-thumb, your code should be:the_post_thumbnail( 'custom-post-thumb' );A typo here (like
custom-post-thumbs) would make WordPress fall back to the default thumbnail, which might be set to soft crop.Check server file permissions
If your server doesn’t have write access to thewp-content/uploadsfolder, WordPress can’t generate the new cropped image files. It’ll fall back to scaling the original image (soft crop) instead. Ensure youruploadsfolder has permissions set to 755, and individual files to 644.Quick check core media settings
While your custom size should override this, sometimes the core “Thumbnail size” setting in Settings > Media can have unexpected interactions. Make sure the “Crop thumbnail to exact dimensions (hard crop)” box is checked there—though this shouldn’t affect custom sizes, it’s a quick check to eliminate variables.
内容的提问来源于stack exchange,提问作者valentina.a87

