Comments on: How to Render Your Own WordPress Photo Gallery Adventures in WordPress Thu, 01 Oct 2015 04:59:03 +0000 hourly 1 By: Dave McCourt Sun, 27 Jul 2014 14:38:26 +0000 Ket, if you return the output and the use the_content() filter, it works inline (ie wherever you put your gallery in the post editor):

add_shortcode('gallery', 'parse_gallery_shortcode');

function gallery_output_in_the_content($content) {
$g = parse_gallery_shortcode();
$custom_content = $g;
$custom_content .= $content;
return $custom_content;

add_filter('the_content', 'gallery_output_in_the_content');

function parse_gallery_shortcode($atts) {
… as above but with this extra code:

$gal .= '';

foreach ($images as $image) {
$caption = $image->post_excerpt;

$description = $image->post_content;
if($description == '') $description = $image->post_title;

$image_alt = get_post_meta($image->ID,'_wp_attachment_image_alt', true);

// render your gallery here
$gal .= '';
$img_meta = wp_get_attachment_metadata($image->ID);
$img = wp_get_attachment_image_src($image->ID, 'gallery-small');
$img_big = wp_get_attachment_image_src($image->ID, 'gallery-big');
$gal .= '';
if (strlen($caption) > 0) $gal .= '' . $caption . '';
$gal .= '';

$gal .= '';

return $gal;

By: ket Sun, 25 May 2014 13:30:09 +0000 This code pushes text down to below the gallery. How to show gallery below or between text content.

By: Leon Wed, 19 Mar 2014 17:12:23 +0000 This example been extremely helpful, thank you!

By: Jimmy Sun, 24 Nov 2013 02:16:17 +0000 Hi there,

trying to display the gallery – as in the kin theme.

i am using wordpress 3.7

I created the plugin and added the first bit

then i added the second bit got errors
so i tried to add it to my functions file got the same error

tried to paste it into the page template not working there

any help would be great

By: Elliot Fri, 08 Nov 2013 13:24:40 +0000 This looks like a great solution, but when I activate the plugin, all the images in the editor’s Media popup disappear. Any idea why this might be happening?

By: ShibaShake Sat, 19 Oct 2013 04:11:25 +0000 This is an older article, written before the 3.5 update where individual image ids are specified, rather than using the parent-attach system. Refer to for a summary of shortcode history and the old vs. new media flow.

ADD: I have just updated the article above to handle id lists.

By: Nicholas Sat, 19 Oct 2013 02:57:31 +0000 Hey I don’t mean to criticize but your code is really not doing the right thing. Firstly as some other comments shared, you are pulling all attachments inside the post, not just from that gallery. The other problem with doing this is the function will no longer respects the order by which the images were set up in the gallery; it is passed as $atts to the shortcode function but disregarded completely.

By: Colir Wed, 25 Sep 2013 12:32:27 +0000 Hi,
thanks for the tips.
However i’ve a problem. i’have multiple gallery in a post, and with your code, each gallery display all attachment image to the post.
How to only have the images that are in each gallery ?

By: Darzan Fri, 09 Aug 2013 08:38:44 +0000 Hi,
I just need a line of code to write instead of your “render your gallery here” only to publish the images, but I can’t understand which variable to use!
I’m not so good with PHP…
Can you please help?

By: NCPR Mon, 08 Apr 2013 13:30:34 +0000 Question; after doing all of this I still cannot scroll through my photos that are in my gallery. There is no “next” button. When I click on an image it just loads that one image and I have to click the back button and find where I was in the gallery to click on the next one. Is there an easy way to fix this?