WordPress并不能很容易地修改gallery shortcode. 一些属性:
感谢用户peterbra 真的把整件事放在一起了a year ago.感谢用户birgire 因为我想出了a solution 以有意义的方式添加属性除了birgires(据我所知),另一个选择是通过复制核心的现有代码来重建短代码media.php file 这是一种痛苦。
首字母上需要注意的一些事情additional_gallery_settings()
函数,来自peterbra:
在tmpl-
前缀是必需的你的领域应该有data-setting
属性只需在functions.php
文件:
/**
* Set up the new field in the media module.
*
* @return void
*/
function additional_gallery_settings() {
?>
<script type="text/html" id="tmpl-custom-gallery-setting">
<span>Style</span>
<select data-setting="style">
<option value="default-style">Default Style</option>
<option value="custom-style">Custom Style</option>
<option value="ie7-style">IE7 Style</option>
</select>
</script>
<script type="text/javascript">
jQuery( document ).ready( function() {
_.extend( wp.media.gallery.defaults, {
style: \'default-style\'
} );
wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend( {
template: function( view ) {
return wp.media.template( \'gallery-settings\' )( view )
+ wp.media.template( \'custom-gallery-setting\' )( view );
}
} );
} );
</script>
<?php
}
add_action( \'print_media_templates\', \'additional_gallery_settings\' );
/**
* HTML Wrapper - Support for a custom class attribute in the native gallery shortcode
*
* @param string $html
* @param array $attr
* @param int $instance
*
* @return $html
*/
function customize_gallery_abit( $html, $attr, $instance ) {
if( isset( $attr[\'style\'] ) && $style = $attr[\'style\'] ) {
// Unset attribute to avoid infinite recursive loops
unset( $attr[\'style\'] );
// Our custom HTML wrapper
$html = sprintf(
\'<div class="wpse-gallery-wrapper-%s">%s</div>\',
esc_attr( $style ),
gallery_shortcode( $attr )
);
}
return $html;
}
add_filter( \'post_gallery\', \'customize_gallery_abit\', 10, 3 );