Title: WordPress Gallery inside the PHP template
Last modified: March 5, 2018

---

# WordPress Gallery inside the PHP template

 *  [bluedrag](https://wordpress.org/support/users/bluedrag/)
 * (@bluedrag)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/wordpress-gallery-inside-the-php-template/)
 * I currently have a number of posts using featured images (full sized on the post
   page, thumbnail size on the category page) and I would like to add a a gallery
   to a few of the posts.
 * In order to lay out the post the way I would like, I need the gallery grouped
   with the featured image, the easiest way to do this would be to the gallery to
   the actual PHP page inside the same <div> as the featured image code. Is there
   any way to do this? Or am I forced to use the gallery shortcode.

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/wordpress-gallery-inside-the-php-template/#post-10046191)
 * You are not forced to do anything! 🙂
 * You could directly call the gallery’s shortcode handler and echo out the return.
   Or make a copy of the handler, edit it any way you want, then call/echo that 
   instead. Or use another gallery plugin altogether.
 * I’m not quite sure what you are really asking. I think you want the gallery shortcode
   output to occur with some template output instead of within post content. Perhaps
   the easiest way to do so is:
    `echo do_shortcode('[gallery]');` This must be 
   within “The Loop”. Outside the loop, call gallery_shortcode() (the shortcode 
   handler) and pass the desired post ID as the “id” argument.
 * By doing this you lose the ability to edit the gallery through the usual media
   library interface. As a workaround, temporarily add “[gallery]” to post content,
   edit the gallery as needed, then remove “[gallery]“.

Viewing 1 replies (of 1 total)

The topic ‘WordPress Gallery inside the PHP template’ is closed to new replies.

## Tags

 * [featured image](https://wordpress.org/support/topic-tag/featured-image/)
 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/wordpress-gallery-inside-the-php-template/#post-10046191)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
