С помощью фильтра
post_gallery
.
Пример:
<?php
function my_post_gallery( $output, $attr, $instance ) {
$_attachments = get_posts( array('include' => $attr['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => $attr['orderby']) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
if ( empty( $attachments ) ) {
return '';
}
ob_start();
?>
<div class="gallery">
<?php
foreach ( $attachments as $i => $image ) :
$url = wp_get_attachment_url( $image->ID );
?>
<a href="<?php echo $url; ?>" class="gallery-item">
<?php echo wp_get_attachment_image( $image->ID, 'thumbnail' ); ?>
</a>
<?php endforeach; ?>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_filter( 'post_gallery', 'my_post_gallery', 10, 3 );