根据Galleria插件与附件图像过滤器的交互方式,您应该能够使用wp_get_attachment_image_attributes
滤器
显然,对于使用wp_get_attachment_image()
, 但它会满足你的要求。
/**
* Filter attributes for the current gallery image tag.
*
* @param array $atts Gallery image tag attributes.
* @param WP_Post $attachment WP_Post object for the attachment.
* @return array (maybe) filtered gallery image tag attributes.
*/
function wpdocs_filter_gallery_img_atts( $atts, $attachment ) {
if ( $full_size = wp_get_attachment_image_src( $attachment->ID, \'full\' ) ) {
if ( ! empty( $full_size[0] ) ) {
$atts[\'data-big\'] = $full_size[0];
}
}
return $atts;
}
add_filter( \'wp_get_attachment_image_attributes\', \'wpdocs_filter_gallery_img_atts\', 10, 2 );
它使用标准设置为库输出以下标记:
<div class="gallery galleryid-2160 gallery-columns-3 gallery-size-thumbnail" id="gallery-1">
<figure class="gallery-item">
<div class="gallery-icon landscape">
<a href="http://...image1.png"><img width="150" height="150" data-big="http://...image1.png" alt="" class="attachment-thumbnail" src="http://...image1-150x150.png"></a>
</div>
</figure>
<figure class="gallery-item">
<div class="gallery-icon landscape">
<a href="http://...image2.png"><img width="150" height="150" data-big="http://...image2.png" alt="" class="attachment-thumbnail" src="http://...image2-150x150.png"></a>
</div>
</figure>
<figure class="gallery-item">
<div class="gallery-icon landscape">
<a href="http://...image3.png"><img width="150" height="150" data-big="http://...image3.png" alt="" class="attachment-thumbnail" src="http://...image3-150x150.png"></a>
</div>
</figure>
</div>