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.
Related Posts:
- Remove the Featured Image Meta Box
- How to generate a featured image from a video embeded in a metabox
- Change headline text for post thumbnail meta box
- Show preview of post changes on page
- Set Default Admin Screen options & Metabox Order
- How to set default screen options?
- Does WordPress have a “Form API”?
- Metabox with checkbox is not updating
- Hiding a theme’s meta box
- Access the environment of an admin page from another admin page
- Add filter ‘wpautop’ to meta box textarea
- Getting jQuery sortable items in custom metabox
- meta content on required pages
- get_post_meta doesn’t work
- Dynamically Creating Meta Boxes
- Remove border on custom meta box
- Create a page Meta Box listing all blog users
- remove_meta_box for all post types doesn’t seem to work
- Position right sidebar metabox right below the publish metabox?
- MetaBox Layout for all users
- How to store multiple input values with same meta_key
- Adding a custom field or metabox to the post-thumbnail widget?
- post-excerpt not one of the options under screen options
- How to add multiple featured image in meta box in post editor?
- How to remove/hide the predictive autocomplete popup when I type in the tag/term metabox
- metabox upload file
- How to put Periods and Spaces for Array Values (Meta Key)
- How to add a SAVE button to replace PUBLISH on a custom post type?
- Why does get_post_meta not work with the posts page?
- Add_meta_box not appearing, but does appear in screen options
- Change the post date from a meta box
- update_post_meta and get_post_meta not working
- Convert textarea with wp_editor
- Metabox saves on Update or Publish, but not on Saving Draft
- metabox with custom post type values
- Checkbox on a meta box using CMB2 Plugin
- Set default post author to none on new post
- How to detect if metabox content was updated by the user
- Remove anchor tag from meta box link
- Adding metabox to wordpress plugins menu page
- How to add select list to meta box field?
- Get meta fields by meta box id
- cannot grab post meta from extended Walker_Category class properly
- Resetting admin post form on JS validation fail
- How do you List all Sidebars in a Metabox
- Condition display metabox in case the post is saved
- Save meta value as an array of arrays
- How to remove some metaboxes for CPTs?
- How to add metabox ONLY to specific WooCommerce product type [closed]
- Add metabox without the container
- input radio ‘checked’ saves, but select option ‘selected’ doesn’t
- wpalchemi metabox doesn’t show value from my post type
- How to use Gutenberg in CMB2?
- edit_page or edit-pages for current_user_can()?
- Editor meta box Showing but not saving
- How can i get multi checkboxes value in metbox?
- Insert media button will always add into the same tinyMCE editor
- Change the title of an Administration Panel
- echo the value of a a meta select box
- save radio button selection in post-meta on submit
- How to display multiple $meta_boxes into separate tables
- ShortCut on meta boxes
- How to add a textarea to only one of the fields of this custom metabox?
- Custom Meta Data is not being saved
- How to add Support to show Fullwidth Featured Image of Custom Post Types in WordPress.?
- how to update post content field in wordpress
- How to ‘clone’ select metabox options with a callback function? [closed]
- Post and Pages section inside WordPress admin are completely blank
- Saving multiple fields (dropdown and text) in custom metabox
- How to create a custom metabox like the wordpress provided tag metabox?
- Update Post meta with custom variable
- display all registered meta boxes
- where can i see the registered new field for posts using register_meta() ?
- update_post_meta doesn’t work
- featured image in custom poste type (backend)
- duplicate featured image functionality in custom meta box
- Is there default meta boxes types that handles types and sanitization?
- how to update editor content from metabox
- Resposive admin classes?
- Disable loading Thumbnail On Mobile [closed]
- Only allow one meta key value per post in a category
- Make metabox always be on top (sticky)
- Ridiculous problem with CDATA [duplicate]
- Can’t save drop down select date in meta boxes
- WordPress check if value equals and echo “checked”
- Custom metabox for file upload return empty filename
- Video slideshow
- Meta Box Value not saving / populating?
- Customer portal (posts as checklist)
- How to set default screen options?
- Customized featured image doesn’t refresh in post admin metabox after upload/insert
- Reload meta box content with AJAX
- why esc_url not working in smartmetabox
- Change Default Custom Fields Metabox Name on cctm plugin
- How to create metabox that can be queried in the database?
- Form submit from modal window to parent window
- How to display meta box data using “Meta boxes as needed”
- Allow iframe in custom meta box
- Datepicker altField and altFormat to save a new meta key/value in a post?
- Metaboxes – why they don’t render php in expected manner?