Created
November 1, 2013 21:30
-
-
Save bradyvercher/7272257 to your computer and use it in GitHub Desktop.
WordPress: Use HiDPI thumbnails with the same aspect ratio as the original image in gallery shortcodes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Width is 2x the max that should ever show. | |
// Height is really tall so it'll never be cropped vertically. | |
add_image_size( 'gallery-thumbnail', 920, 5000 ); | |
/** | |
* Set the default gallery size to 'gallery-thumbnail'. | |
* | |
* @param array $out Combined and sanitized attributes list. | |
* @param array $pairs All supported attributes and their defaults. | |
* @param array $atts User-defined attributes in the shortcode tag. | |
* @return array | |
*/ | |
function prefix_gallery_shortcode_attributes( $out, $pairs, $atts ) { | |
if ( empty( $atts['size'] ) || 'thumbnail' == $atts['size'] ) { | |
$out['size'] = 'gallery-thumbnail'; | |
} | |
return $out; | |
} | |
add_filter( 'shortcode_atts_gallery', 'prefix_gallery_shortcode_attributes', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment