Skip to content

Instantly share code, notes, and snippets.

@Narayon
Last active April 8, 2018 01:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Narayon/88102cae0315130c58fb to your computer and use it in GitHub Desktop.
Save Narayon/88102cae0315130c58fb to your computer and use it in GitHub Desktop.
Wordpress: add image size
<?php
//set custom sizes
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped)
}
//rename custom sizes for the Dashboard, with translation
add_filter('image_size_names_choose', 'PREFIXIT_image_sizes');
function PREFIXIT_image_sizes($sizes) {
$addsizes = array(
"new-size" => __( "New Size")
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}
//unset default wordpress sizes
function PREFIXIT_filter_image_sizes( $sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'PREFIXIT_filter_image_sizes');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment