2

I need to change the default gallery shortcode settings so that "columns" = 5 & "link" = 'file'.

Which filter to add to the file functions.php?

Source code:

$atts = shortcode_atts( array(
            'order'      => 'ASC',
            'orderby'    => 'menu_order ID',
            'id'         => $post ? $post->ID : 0,
            'itemtag'    => $html5 ? 'figure'     : 'dl',
            'icontag'    => $html5 ? 'div'        : 'dt',
            'captiontag' => $html5 ? 'figcaption' : 'dd',
            'columns'    => 3,
            'size'       => 'thumbnail',
            'include'    => '',
            'exclude'    => '',
            'link'       => ''
    ), $attr, 'gallery' );
0

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

To modify the [gallery] 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 [gallery] 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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.