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.
Opens WPIDE on
Code
// 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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.