the_post_thumbnail $size参数失效,如何添加完整分辨率图片尺寸?
Hey there, let's work through why changing the size parameter to 'full' didn't fix your cropping problem, and how to get full-resolution images displaying properly.
First, a quick note: The 'full' size should theoretically pull the original, uncropped image you uploaded—but sometimes themes or plugins override this default behavior, or your existing media doesn't have the full-size variant generated correctly. Here are a few reliable solutions:
1. Register a Custom Uncropped Image Size
If your theme is enforcing cropping even for the 'full' size, create a brand new image size that explicitly disables cropping. Add this code to your theme's functions.php file (use a child theme if you can, so changes don't get wiped on theme updates):
add_action( 'after_setup_theme', 'register_uncropped_image_size' ); function register_uncropped_image_size() { // Name: 'uncropped-full', width/height 0 = no restrictions, crop = false add_image_size( 'uncropped-full', 0, 0, false ); }
After adding this, you'll need to regenerate thumbnails for existing images (use the Regenerate Thumbnails plugin to do this in bulk). Then update your the_post_thumbnail call to use this new size:
the_post_thumbnail( 'uncropped-full', $attr );
2. Bypass the Thumbnail Function Altogether
If you want to guarantee you're getting the original image, skip the_post_thumbnail entirely and manually output the image tag using the raw attachment URL:
// Get the ID of the post's featured image $thumbnail_id = get_post_thumbnail_id(); // Grab the original image URL $full_image_url = wp_get_attachment_image_url( $thumbnail_id, 'full' ); // Only output the image if the URL exists if ( $full_image_url ) { echo '<img src="' . esc_url( $full_image_url ) . '" alt="' . esc_attr( get_the_title() ) . '" />'; }
This method avoids any theme or plugin filters that might be altering the thumbnail output.
3. Check for Theme/Plugin Overrides
If 'full' isn't working, double-check your theme's functions.php for any code that modifies default image sizes. Look for lines like:
add_image_size( 'post-thumbnail', 800, 600, true ); // Forces cropping // Or even something overriding the 'full' size (rare but possible) update_option( 'thumbnail_size_w', 1000 );
If you find such code, you can adjust the crop parameter to false or remove the size registration entirely.
内容的提问来源于stack exchange,提问作者Alexander Myrvold

