Skip to content

Instantly share code, notes, and snippets.

@jonbrockett
Created January 17, 2019 14:27
Show Gist options
  • Select an option

  • Save jonbrockett/2643353ce93fc3ef805012bd0dd2906c to your computer and use it in GitHub Desktop.

Select an option

Save jonbrockett/2643353ce93fc3ef805012bd0dd2906c to your computer and use it in GitHub Desktop.
WP - Adjust Media Library Thumbnail Sizes

You will generally want to use this when adjusting the medium and large size in the WP settings. Otherwise a much larger image will be used, bogging down the media library load.

Also, if you unset the medium file size, the full image size will be used. All the more important to use it for that.

To use in the FoundationPress theme, add before you register the new image sizes for use in the add media modal in wp-admin.

Or more generically, add to the functions.php file.

// Adjust media library to new sizes
function ajust_media_library( $response, $attachment, $meta ) {
if (!empty($response)) {
$sizes = array(
'xsmall', // Custom size
'small', // Custom size
'medium', // WP default
'large', // WP default
);
while ( count( $sizes ) > 0 ) {
$cur_size = array_pop( $sizes );
if ( isset( $response['sizes'][$cur_size] ) ) {
$response['sizes']['medium'] = $response['sizes'][$cur_size];
}
}
}
return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'ajust_media_library', 999, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment