Change default settings used by gallery shortcode

The shortcode_atts_{$shortcode} filter allows default parameters to be modified for shortcodes.

To modify the shortcode, we’ll use the shortcode_atts_gallery filter.

Here is an example that changes the defaults for the columns and link parameters in the shortcode. Note that if the user specifies values for these parameters, those values will be used; we’re just changing the defaults.

add_filter( 'shortcode_atts_gallery', 'wpse246345_shortcode_atts_gallery', 10, 4 );
function wpse246345_shortcode_atts_gallery( $out, $pairs, $atts, $shortcode ) {

    if ( ! isset( $atts['columns'] )  ) {
        $out['columns'] = 5;
    }

    if ( ! isset( $atts['link'] ) ) {
        $out['link'] = 'file';
    }   

    return $out;
}

Leave a Comment