您可以使用该功能[wp_calculate_image_srcset()][1], 用于返回srcset attribute 值,则需要存在不同的大小,否则函数返回false。
下面是与srcset的链接的样子,
<img class="alignnone size-full wp-image-122491 "
src="http://example.com/wp-content/uploads/2016/03/C0101-012.jpg" alt="C0101-012" width="2000" height="1200"
srcset="http://example.com/wp-content/uploads/2016/03/C0101-012.jpg 2000w, http://example.com/wp-content/uploads/2016/03/C0101-012-656x394.jpg 656w, http://example.com/wp-content/uploads/2016/03/C0101-012-1024x614.jpg 1024w, http://example.com/wp-content/uploads/2016/03/C0101-012-1080x648.jpg 1080w"
sizes="(max-width: 2000px) 100vw, 2000px" />
 使用srcset,浏览器可以确定哪个图像是最好的。在不支持srcset的浏览器上,src属性的值将用作图像src默认图像(主要浏览器支持srcset)。
这里有一个小例子,我需要添加一个随机的大截面图像,并为这个图像生成新的属性。介质来自通用阵列,我简化了所有功能,
function enqueue_front_page_srcset_js(){
    $random_array = array(\'id\'=>\'1234\', \'url\'=>\'http://example.com/wp-content/uploads/2016/03/C0948b-162.jpg\', ...);
    $random_key = array_rand($images_array, 1);
    $random_image = $images_array[$random_key];
    $size_array = array(array(656, 394), array(1024, 614),array(1080, 648));
    $image_src = $random_image[\'url\'];
    $image_meta = wp_get_attachment_metadata( $random_image[\'id\'] );
    $img_srcset = wp_calculate_image_srcset( 
                   $size_array, 
                   $image_src, 
                   $image_meta, 
                   $random_image[\'id\'] 
    );
    wp_register_script( \'brozzme-random-image\',  get_stylesheet_directory_uri() . \'/js/jquery.b7e.random.image.js\', array( \'jquery\' ), false, true );
    wp_localize_script(
        \'b7e-random-image\',
        \'randomImage\',
        array(
            \'newSrc\'=> $image_src,
            \'randomSrcset\'=> $img_srcset
        )
    );
    wp_enqueue_script(\'b7e-random-image\');
}
add_action(\'wp_enqueue_scripts\', \'enqueue_front_page_srcset_js\');
 jQuery脚本
jQuery(document).ready(function ($) {
    var newSrc = randomImage.newSrc;
    var newSrcset = randomImage.randomSrcset;
    $( ".et_pb_fullwidth_image_0 img" ).attr( "src", newSrc );
    $( ".et_pb_fullwidth_image_0 img" ).attr( "srcset", newSrcset );
});
 希望有帮助!