Created
April 23, 2021 15:53
-
-
Save damadorPL/44acb1a95ff0772a211625fc98e161b6 to your computer and use it in GitHub Desktop.
custm upload images
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
/* | |
* this hook will be fired while you uploading a picture | |
*/ | |
add_filter( 'intermediate_image_sizes', 'misha_reduce_image_sizes' ); | |
function misha_reduce_image_sizes( $sizes ){ | |
/* | |
* $sizes - all image sizes array Array ( [0] => thumbnail [1] => medium [2] => large [3] => post-thumbnail ) | |
* get_post_type() to get post type | |
*/ | |
$type = get_post_type($_REQUEST['post_id']); // $_REQUEST['post_id'] post id the image uploads to | |
foreach( $sizes as $key => $value ){ | |
/* | |
* use switch if there are a lot of post types | |
*/ | |
if( $type == 'page' ) { | |
if( $value == 'regionfeatured' ){ // turn off 'regionfeatured' for pages | |
unset( $sizes[$key] ); | |
} | |
} else if ( $type == 'region' ) { | |
if( !in_array( $value, array('regionfeatured','misha335') ) ){ // for regions turn off everyting except 'regionfeatured' and 'misha335' | |
unset( $sizes[$key] ); | |
} | |
} else { | |
if( $value != 'thumbnail' ){ // turn off everything except thumbnail | |
unset( $sizes[$key] ); | |
} | |
} | |
} | |
return $sizes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment