Last active
April 8, 2018 01:53
-
-
Save Narayon/88102cae0315130c58fb to your computer and use it in GitHub Desktop.
Wordpress: add image size
This file contains hidden or 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 | |
//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