Define size for `get_post_gallery_images`, they seem to have been resized to 150×150

I’m using get_post_gallery_images and it’s spitting images out as 150×150. It doesn’t look like it takes a size parameter, so I assumed it would just spit out the largest image or preferably one of my defined sizes. 150×150 is too small though, is there somewhere I can declare what size gallery images I want?

For instance I’m doing:

<?php
$gallery = get_post_gallery_images( $post ); 
foreach ($gallery as $img) { ?>
    <li><img src="https://wordpress.stackexchange.com/questions/141896/<?php echo $img; ?>" /></li>
<?php } ?>

All of these images are coming out as 150×150, is there something I’m missing?

3 Answers
3

If you want get_post_gallery_images to give you full size images, you can use the following:

// Use full size gallery images for the next gallery shortcode: 
add_filter( 'shortcode_atts_gallery', 'wpse_141896_shortcode_atts_gallery' );
// Your code:
$gallery = get_post_gallery_images( $post ); 
foreach ($gallery as $img) { ?>
    <li><img src="https://wordpress.stackexchange.com/questions/141896/<?php echo $img; ?>" /></li>
<?php } 

where

/**
 * Set the size attribute to 'full' in the next gallery shortcode.
 */
function wpse_141896_shortcode_atts_gallery( $out )
{
    remove_filter( current_filter(), __FUNCTION__ );
    $out['size'] = 'full';
    return $out;
}

In this example we remove the filter after using it once, so it will not affect your other galleries.

This way you don’t have to include the size="full" attribute in your gallery shortcodes,

Leave a Comment