I'm trying to style my theme without resorting to custom fields. For gallery posts type, most premium themes are using custom field which is the method I used till now. With it, I could then retrieve the attachment ID's and display the images in a slideshow above the post title & content.

However this results in theme lock, and I was wondering if there is any way to do the below:

  1. Retrieve the first gallery shortcode used in a post to output the images as slideshow above the Post title and
  2. also remove the shortcode from within the post so it is not displayed again in the content.

I understand it would involve lot of code so if anyone could just point me in the right direction would be appreciated. I know bit of PHP and can tweak code but not great with creating something from scratch.

1 Answer 1


I am also seeking the same solution. I am going to create a gallery filter function - an extension to this. Do you want to collaborate?

function get_post_gallery( $post = 0, $html = true ) {
$galleries = get_post_galleries( $post, $html );
$gallery = reset( $galleries );

 * Filter the first-found post gallery.
 * @since 3.6.0
 * @param array       $gallery   The first-found post gallery.
 * @param int|WP_Post $post      Post ID or object.
 * @param array       $galleries Associative array of all found post galleries.
return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );
  • Would love to collaborate but I'm not that good with programming. I'm more of a theme designer. Aug 18, 2014 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.