Skip to content

Instantly share code, notes, and snippets.

@hatsumatsu
Last active December 1, 2020 17:54
Show Gist options
  • Save hatsumatsu/cee847a90721ae5faaecc88b159a3c9e to your computer and use it in GitHub Desktop.
Save hatsumatsu/cee847a90721ae5faaecc88b159a3c9e to your computer and use it in GitHub Desktop.
<?php
add_filter( 'wp_get_attachment_metadata', function( $data ) {
if( is_admin() ) {
return $data;
}
if( !array_key_exists( 'file', $data ) ) {
return $data;
}
$mime = wp_check_filetype( $data['file'] )['type'];
if( $mime !== 'image/gif' ) {
return $data;
}
$data['sizes'] = array(
'medium' => array(
'file' => basename( $data['file'] ),
'width' => $data['width'],
'height' => $data['height'],
'mime-type' => $mime
)
);
return $data;
}, 1000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment