Title: Custom Gallery (using WordPress&#039; native gallery functionality)
Last modified: August 20, 2016

---

# Custom Gallery (using WordPress' native gallery functionality)

 *  Resolved [traumm](https://wordpress.org/support/users/traumm/)
 * (@traumm)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/custom-gallery-using-wordpress-native-gallery-functionality/)
 * Hi all,
 * I’m planning on using WP’s new media manager / gallery in order to control a 
   custom gallery that will be different on each page.
 * However, instead of add the new gallery to the content area, it needs to appear
   elsewhere on the page.
 * I’ve got this working firstly by removing the default Gallery shortcode (to prevent
   it from showing up in the front-end content area)
 * Then in my functions file I’ve added this:
 *     ```
       function customGallery($output, $attr) {
   
           	$order = 'DESC';
   
           	$orderby = 'post__in';
           	$include = $attr['ids'];
   
           	$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
           	$attachments = array();
           	foreach ( $_attachments as $key => $val ) {
           		$attachments[$val->ID] = $_attachments[$key];
           		}
   
           	if ( empty($attachments) ) return;
   
           	foreach ( $attachments as $id => $attachment ) { ?>
           		<img src="<?php echo wp_get_attachment_url( $id ); ?>" alt="<?php echo $attachment->post_excerpt; ?>" />
           	<?php }
           }
       ```
   
 * My question is, what am I passing to this function in my template?
 * At the moment this snippet in page.php gets all image attachments, not just the
   ones attached to the page in question.
 * `<?php customGallery($output, $attr); ?>`
 * Hopefully someone can help here – am assuming it’s a case of passing an array
   of page-specific values to $attr
 * Any help much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [paulwpxp](https://wordpress.org/support/users/paulwp/)
 * (@paulwp)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/custom-gallery-using-wordpress-native-gallery-functionality/#post-3465155)
 * What you need is just this (put in the template)
 *     ```
       <?php echo do_shortcode('[gallery]'); ?>
       ```
   
 * By default, it will display only images uploaded through that post/page, in 3
   columns formats, ordered by menu order.
 * You can also use all the arguments that gallery shortcode accepts, for example
   if you want the gallery to display in 5 columns.
 *     ```
       <?php echo do_shortcode('[gallery columns="5"]'); ?>
       ```
   
 * You can also use the `id` of the post/page too, it will display images uploaded
   via that post/page only.
 * The main documentation is here.
    [http://codex.wordpress.org/Gallery_Shortcode](http://codex.wordpress.org/Gallery_Shortcode)
 *  Thread Starter [traumm](https://wordpress.org/support/users/traumm/)
 * (@traumm)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/custom-gallery-using-wordpress-native-gallery-functionality/#post-3465163)
 * Hi, thanks for the reply – apologies if I didn’t make this clear…
 * Simply using do_shortcode won’t prevent the gallery from appearing in the content
   area.
 * Pretty sure I was almost there with the initial plan, I just need to know how
   to pass attachment values to the new function.
 * Thanks!
 *  Thread Starter [traumm](https://wordpress.org/support/users/traumm/)
 * (@traumm)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/custom-gallery-using-wordpress-native-gallery-functionality/#post-3465174)
 * For anyone else who may be interested, I found the answer here:
 * [http://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work](http://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Gallery (using WordPress' native gallery functionality)’ is closed
to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [gallery](https://wordpress.org/support/topic-tag/gallery/)

 * 3 replies
 * 2 participants
 * Last reply from: [traumm](https://wordpress.org/support/users/traumm/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/custom-gallery-using-wordpress-native-gallery-functionality/#post-3465174)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
