# Link Gallery Images to the Full File by Default

> Makes [gallery] shortcodes link each thumbnail to the full-size image and use medium-size thumbnails, unless the shortcode sets its own options.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: gallery, images, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gallery-shortcode-defaults/

## Code

```php
// Defaults for galleries that do not set these options.
$wpide_gallery_defaults = array(
    'link'    => 'file',
    'size'    => 'medium',
    'columns' => 3,
);

add_filter( 'shortcode_atts_gallery', function ( $out, $pairs, $atts ) use ( $wpide_gallery_defaults ) {
    foreach ( $wpide_gallery_defaults as $key => $value ) {
        if ( ! isset( $atts[ $key ] ) ) {
            $out[ $key ] = $value;
        }
    }

    return $out;
}, 10, 3 );
```

## Notes

Applies to classic [gallery] shortcodes; Gallery blocks keep the settings chosen in the editor.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Link Gallery Images to the Full File by Default" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
