Home Projects WordPress’ Gallery feature display full images instead of thumbs

WordPress’ Gallery feature display full images instead of thumbs

by Philip Sellers

I’ve encountered an issue with recent version of Wordpress which I believe I have found a fix for.  I’m a big fan of the new gallery abilities that have been built into the 2.5 and 2.6 versions of Wordpress.  To me, they easily allow for uploading and posting photo galleries and work great – at least until recently.  Something in the underlying code broke with one of the 2.5 releases and has yet to be fixed.

I had setup a Wordpress site for a friend’s church.  It works well and she wanted to be able to post photos from their events and get-togethers.  So, I logically upgraded her to the latest, greatest Wordpress to make use of the gallery feature.  But, then the problem occurred.  After using the gallery shortcode, the images displayed were not the thumbnail images, but rather the fullsize images.  And, no setting seemed to fix this problem.

After getting fairly frusterated with the problem last night, I decided to delve into the code and trace through it to find the cause.  After tracing through many functions, I located the problem in the wp_get_attachment_metadata function.  This function was invoked but returned no usable information for the attachment (image, movie, etc.).  Now, this is where I stopped, because I got the desired effect.  The function definition is the following:

function wp_get_attachment_metadata( $post_id, $unfiltered = false ) {

A conditional statement later in the function looks to the $unfiltered variable.  Because it was defaulting to false, it never returned the array of values that it had retrieved.  It instead attempted to “apply_filters” to the array.  The apply_filters apparently did not work correctly.  So, a simple change in the declaration from false to true fixes our thumbnail image problem in Wordpress 2.6.2 and 2.6.3.

The wp_get_attachment_metadata function is located in /wp-includes/post.php.   I hope that maybe this will help someone else.  AND, I will be looking into the apply_filters function more to see what its actually supposed to be doing there…

You may also like