我需要更改默认的库快捷码设置,以便“columns”=5(&;“link”=“文件”。
要添加到文件的筛选器functions.php?
源代码:
$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\' );
 
                SO网友:Dave Romsey
                这个shortcode_atts_{$shortcode} 过滤器允许修改短代码的默认参数。
要修改[gallery] shortcode,我们将使用shortcode_atts_gallery 滤器
下面是一个更改columns 和link 中的参数[gallery] 短代码。请注意,如果用户指定这些参数的值,则将使用这些值;我们只是在更改默认值。
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;
}