我用一个生成整个标记的新短代码来解决这个问题。像这样:
function generate_image_tag($atts) {
$atts = shortcode_atts( array(
\'img\' => \'\',
\'title\' => \'\',
\'theme_url\' => get_bloginfo(\'template_url\'),
), $atts );
//File path details
$file_info = pathinfo($atts[\'img\']);
$file_dir = $file_info[\'dirname\'] != \'.\' ? $file_info[\'dirname\'].\'/\' : \'\';
$file_url = $file_dir . $file_info[\'filename\'];
$output = \'<picture>
<source srcset="\'.$atts[\'theme_url\'].\'/images/\'.$file_url.\'.webp" type="image/webp">
<img src="\'.$atts[\'theme_url\'].\'/images/\'.$atts[\'img\'].\'">
</picture>\';
return $output;
}
add_shortcode(\'generate_image\', \'generate_image_tag\');
[generate_image img="image.png" title="Title"]
我认为WP中可能有问题,这是一个bug。无快捷码
<source>
标签问候!:)