Make WordPress Core

Opened 11 years ago

Last modified 5 years ago

#24815 new defect (bug)

get_the_post_thumbnail() fetches full sized image if 'post-thumbnail' custom size not defined in theme

Reported by: jonnyauk's profile Jonnyauk Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9
Component: Media Keywords: needs-codex has-patch needs-refresh
Focuses: Cc:


In wp-includes/post-thumbnail-template.php the $size default value is set as 'post-thumbnail' in the following function:

  • get_the_post_thumbnail()

Expected behaviour
Expected behaviour would be to return the image at 'post-thumbnail' dimensions - however, if this is not set in the theme via:

  • set_post_thumbnail_size() function
  • add_image_size() function

it returns the full sized sized image begin displayed. I'd expect this to return the image at standard 'thumbnail' size, as some people will just add add_theme_support( 'post-thumbnails' ) and not set (or even need) custom dimensions.

Proposal and patch
$size default value should default back to 'thumbnail' for normal expected function behaviour if 'post-thumbnail' specific dimensions have not been set.

I'm not sure if it would be more efficient to test against the global variable that holds these values, or use get_intermediate_image_sizes() as I've used in the patch attached - 2nd opinion please?

Attachments (1)

v1.patch (886 bytes) - added by Jonnyauk 11 years ago.
Patch v1 - uses get_intermediate_image_sizes()

Download all attachments as: .zip

Change History (6)

11 years ago

Patch v1 - uses get_intermediate_image_sizes()

#1 @Jonnyauk
11 years ago

I think the alternative approach would use the global $_wp_additional_image_sizes

#2 @nacin
11 years ago

  • Version changed from trunk to 2.9

Originally post-thumbnail-template.php was only included if the theme actually supported post thumbnails. The only reason why it isn't is because the conditional loading of the file was silly for opcode caching purposes. I'm not sure there is anything we should do here. 'post-thumbnail' is realistically required for these functions.

#3 @Jonnyauk
11 years ago

I understand where you are coming from on this, thank you for your feedback. However, in the patch I still check against 'post-thumbnail', so there won't be any compatibility issues.

It seems a-little strange behaviour to me to have to define another image size for 'post-thumbnail' for this to function correctly, I'd expect it to default to standard thumbnail dimensions (due to the name of the function?)

#4 @alexufo
10 years ago

i agree with this. But better add to core. Full absorb many problem.

Version 0, edited 10 years ago by alexufo (next)

#5 @chriscct7
9 years ago

  • Keywords needs-refresh added; 2nd-opinion removed

Attached patch would need a refresh

Note: See TracTickets for help on using tickets.