最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

images - max_srcset_image_width doesn't work as intended

matteradmin4PV0评论

I register a new image size in my theme, i.e:

add_image_size('home-slide', 1500, 756, true);

and I set the maximum size for the srscet attribute of responsive images to 1024:

function set_max_srcset_image_width( $max_width ) {
   $max_width = 1024;
   return $max_width;
}
add_filter( 'max_srcset_image_width', 'set_max_srcset_image_width' );

Finally, I show my image in the posts loop with:

    <img src="<?php echo wp_get_attachment_image_url( 7, 'home-slide' ) ?>"
 srcset="<?php echo wp_get_attachment_image_srcset( 7, 'home-slide' ) ?>"
 sizes="<?php echo wp_get_attachment_image_sizes( 7, 'home-slide' ) ?>" />

But I get the following markup:

<img src=".jpg" srcset="" sizes="(max-width: 1500px) 100vw, 1500px">

Why?

Post a comment

comment list (0)

  1. No comments so far