get_post_gallery_images returns thumbs . I want full size

The question:

I have the following code on my site.

<?php // image gallery content 
if( has_shortcode( $post->post_content, 'gallery' ) ) {                     
    $gallery = get_post_gallery_images( $post->ID );


    $image_list = '<ul id="cfImageGallery">';                       
    foreach( $gallery as $image ) {// Loop through each image in each gallery
        $image_list .= '<li><img src=" ' . str_replace('-150x150','',$image) . ' " /></li>';
    }
    $image_list .= '</ul>';                     
    echo $image_list;                       
}                         
?>

My problem is that get_post_gallery_images returns thumbs files instead of fill size so Im using the str_replace function to solve it.

How can I make to retrieve the full size urls?

Thanks

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

If you’re working within a template file, this code should work. However, I didn’t test it.

<?php echo do_shortcode(''); ?>

Method 2

@tfer77 has given the right answer. I am here explaining it in a more better way.

You need to add size="full" attribute to the gallery shortcode in the post content like


Now when you use

$gallery = get_post_gallery_images( $post->ID );

You will get full size images. You can check the same by using the filter get_post_gallery

Paste the below code in your theme’s functions.php file.

add_filter( 'get_post_gallery', 'wpse_get_full_size_gallery_images', 10, 3 );
function wpse_get_full_size_gallery_images( $gallery, $post, $galleries ) { 
    var_dump($gallery);
}

and the page where you have used get_post_gallery_images, you will get a image url as

http://www.siteurl.com/wp-content/uploads/2013/10/eiffel-tower.jpg

rather than

http://www.siteurl.com/wp-content/uploads/2013/10/eiffel-tower-150x150.jpg


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment