您可以尝试用以下内容覆盖库短代码:
add_shortcode( \'gallery\', \'custom_gallery_shortcode\' );
其中,快捷码回调为:
/**
* Overwrite the native [gallery] shortcode, to modify the HTML layout.
*/
function custom_gallery_shortcode( $attr = array(), $content = \'\' )
{
$attr[\'itemtag\'] = "li";
$attr[\'icontag\'] = "";
$attr[\'captiontag\'] = "p";
// Run the native gallery shortcode callback:
$html = gallery_shortcode( $attr );
// Remove all tags except a, img,li, p
$html = strip_tags( $html, \'<a><img><li><p>\' );
// Some trivial replacements:
$from = array(
"class=\'gallery-item\'",
"class=\'gallery-icon landscape\'",
\'class="attachment-thumbnail"\',
\'a href=\',
);
$to = array(
\'\',
\'\',
\'class="tnggallery"\',
\'a class="lightbox" href=\',
);
$html = str_replace( $from, $to, $html );
// Remove width/height attributes:
$html = preg_replace( \'/(width|height)=\\"\\d*\\"\\s/\', "", $html );
// Wrap the output in ul tags:
$html = sprintf( \'<ul class="gallery">%s</ul>\', $html );
return $html;
}
修改HTML布局。