$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>metabox - Serving a custom featured image for mobile|Programmer puzzle solving
最新消息: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)

metabox - Serving a custom featured image for mobile

matteradmin8PV0评论

is it a good approach to serve multiple featured images to have a proper scaling?

Right now the featured image size on "Desktop" is up to 1140x250. Pretty wide and will shrink way too far on "Mobile 1", until you can't really recognize the image anymore.

My idea was to just serve a second featured image for mobile phones up to like 500px. The size of this "Mobile 2" featured image would be something like 500x250.

Pro: Ability to serve different images on mobile/desktop and crop/scale ourselves.
Con: Every image needs to be uploaded and edited twice.

Is there a WordPress native way to do this I completely missed?

is it a good approach to serve multiple featured images to have a proper scaling?

Right now the featured image size on "Desktop" is up to 1140x250. Pretty wide and will shrink way too far on "Mobile 1", until you can't really recognize the image anymore.

My idea was to just serve a second featured image for mobile phones up to like 500px. The size of this "Mobile 2" featured image would be something like 500x250.

Pro: Ability to serve different images on mobile/desktop and crop/scale ourselves.
Con: Every image needs to be uploaded and edited twice.

Is there a WordPress native way to do this I completely missed?

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Nov 16, 2018 at 16:32 BensenBensen 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I would do this with Advanced Custom Fields and a Sass mixin:

@mixin image-2x($image, $width, $height) {
  @media (min--moz-device-pixel-ratio: 1.3),
         (-o-min-device-pixel-ratio: 2.6/2),
         (-webkit-min-device-pixel-ratio: 1.3),
         (min-device-pixel-ratio: 1.3),
         (min-resolution: 1.3dppx) {
    background-image: url($image);
    background-size: $width $height;
  }
}
//Usage
div.logo {
  background: url("logo.png") no-repeat;
  @include image-2x("logo2x.png", 100px, 25px);
}

Featured images or native custom fields could also be used instead of ACF. For an automatic solution that removes the need to upload multiple image versions you can use a retina plugin - WP Retina 2x.

Post a comment

comment list (0)

  1. No comments so far