# A gallery grid

> Print a gallery as a responsive grid.

Source: https://uglydev.com/recipes/a-gallery-grid/
Updated: 20 November 2026

![The gallery grid on the site](https://uglydev.com/wp-content/uploads/2026/11/shot-a-gallery-grid-1.webp)

*The gallery grid on the site.*

**Fields.** `gallery` (Gallery, return format **Image ID**).

```php
<?php $images = ugly_get( 'gallery' ); ?>
<?php if ( $images ) : ?>
	<ul class="gallery">
		<?php foreach ( $images as $id ) : ?>
			<li>
				<a href="<?php echo esc_url( wp_get_attachment_image_url( $id, 'full' ) ); ?>">
					<?php echo wp_get_attachment_image( $id, 'medium' ); ?>
				</a>
			</li>
		<?php endforeach; ?>
	</ul>
<?php endif; ?>
```

The order is the one the editor dragged them into.
