I've used this to display the gallery under the content in a few of my website, or in a custom position, you can manipulate it however you need. The only draw back (sort of) is if there are 2 galleries, it will only work with the first gallery.
<?php
get_header();
// Get Post Gallery before The Loop
global $post;
$gallery = get_post_gallery($post->ID);
?>
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
$content = strip_shortcode_gallery( get_the_content() ); // remove Gallery Shortcode
$content = str_replace( ']]>', ']]>', apply_filters( 'the_content', $content ) ); // Resetup Content
echo $content; // Echo Content
<?php endwhile; ?>
<?php endif; ?>
<div id="gallery">
<?php echo $gallery; ?>
</div>
<?php get_footer(); ?>
Functions.php
function strip_shortcode_gallery( $content ) {
preg_match_all( '/'. get_shortcode_regex() .'/s', $content, $matches, PREG_SET_ORDER );
if ( ! empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
if ( 'gallery' === $shortcode[2] ) {
$pos = strpos( $content, $shortcode[0] );
if ($pos !== false)
return substr_replace( $content, '', $pos, strlen($shortcode[0]) );
}
}
}
return $content;
}
get_post_gallery($id)
- WordPress Codex - Otherwise, you would probably have to make a custom plugin, The Gallery is supposed to work in-tangent with The Content but with the function above, you can strip it out and ignore any extra content.get_post_galleries_images
but supply the ID from a different page. Would this orget_post_gallery
still work if I were to modifiy the shortcode to not return anything when a specific template is used?get_post_galler()
inside that specific template?the_content()
though, or would it? The page is supposed to display the gallery, than a bit further downthe_content()
without displaying the gallery again. But I don't want to mess around with the handling of the shortcode to much since on other pages the gallery will have to work the usual way.