在cleaner gallery中。php对cleaner\\u gallery\\u plugin\\u gallery\\u image函数进行更改,该函数从第122行开始,到第151行结束。
我们所做的是在输出带有图像属性的html的两个实例中,将href替换为data href。
function cleaner_gallery_plugin_gallery_image( $image, $id, $attr, $instance ) {
/* If the image should link to nothing, remove the image link. */
if ( \'none\' == $attr[\'link\'] ) {
$image = preg_replace( \'/<a.*?>(.*?)<\\/a>/\', \'$1\', $image );
}
/* If the image should link to the \'file\' (full-size image), add in extra link attributes. */
elseif ( \'file\' == $attr[\'link\'] ) {
$attributes = cleaner_gallery_link_attributes( $instance );
if ( !empty( $attributes ) )
$image = str_replace( \'<a href=\', "<a{$attributes} data-href=", $image );
}
/* If the image should link to an intermediate-sized image, change the link attributes. */
elseif ( in_array( $attr[\'link\'], get_intermediate_image_sizes() ) ) {
$post = get_post( $id );
$image_src = wp_get_attachment_image_src( $id, $attr[\'link\'] );
$attributes = cleaner_gallery_link_attributes( $instance );
$attributes .= " data-href=\'{$image_src[0]}\'";
$attributes .= " title=\'" . esc_attr( $post->post_title ) . "\'";
$image = preg_replace( \'/<a.*?>(.*?)<\\/a>/\', "<a{$attributes}>$1</a>", $image );
}
/* Return the formatted image. */
return $image;
}