How to provide different image sizes depending on the size of the viewport in WordPress?

It may be a very simple question due to less understanding of the procedure, but what I think is NO question is less important .

In WordPress, we have 4 default sizes:

  • Original (as elsewhere) - no cropping
  • Large - usually 1024 times; 1024
  • Medium - usually 300 times; 300
  • A sketch is usually 150 and times; 150 - hard edge.

And we can edit / deactivate all sizes by default, except for the original, and we can add / edit / delete any custom sizes, you can even enable 2x support using custom scripts for widescreen devices. But where my understanding ceased - we have our desired images with their sizes, what now? How can we show / deliver them according to view sizes?

Suppose I have a section where the code is located:

<article class="news">
    <?php the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) ); ?>
    <div class="entry-excerpt"><?php the_excerpt(); ?></div>
</article>

If I need to throw away a 2x (wider) version of the image (instead of a thumbnail), how can I do this?

, PHP JavaScripts, JS - . , JS, ? , .

+4
1

JS, BAD . , CSS . , JS, , .

PHP get_browser (http://php.net/manual/en/function.get-browser.php) - . .

, al- HTML JS , src corect src

:

<img src="" 
     data-full-src=" full-link "
     data-large-src=" large-link "
     data-medium-src=" medium-link "
     data-small-src=" small-link " />

JS:

var image = getElementById( your-img-ID ); //or some other selector
var selectedSrc = "data-full-src";
image.setAttribute('src', image.getAttribute(selectedSrc) );
0

All Articles