Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Created March 15, 2018 14:22
Show Gist options
  • Save vincentorback/85be1e58d28bcffdae585303004e1a5c to your computer and use it in GitHub Desktop.
Save vincentorback/85be1e58d28bcffdae585303004e1a5c to your computer and use it in GitHub Desktop.
Update and force image sizes in WordPress
<?php
add_action( 'switch_theme', function ()
{
update_option('thumbnail_size_w', 500);
update_option('thumbnail_size_h', 500);
update_option('thumbnail_size_cropt', 0);
update_option('medium_size_w', 1000);
update_option('medium_size_h', 1000);
update_option('medium_size_cropt', 0);
update_option('large_size_w', 2000);
update_option('large_size_h', 2000);
update_option('large_size_cropt', 0);
}
add_filter( 'pre_update_option_thumbnail_size_w', 'themename_filter_thumbnail_size_w' );
function themename_filter_thumbnail_size_w( $newvalue ) {
return 500;
}
add_filter( 'pre_update_option_thumbnail_size_h', 'themename_filter_thumbnail_size_h' );
function themename_filter_thumbnail_size_h( $newvalue ) {
return 500;
}
add_filter( 'pre_update_option_thumbnail_crop', 'themename_filter_thumbnail_crop' );
function themename_filter_thumbnail_crop( $newvalue ) {
return 0;
}
add_filter( 'pre_update_option_medium_size_w', 'themename_filter_medium_size_w' );
function themename_filter_medium_size_w( $newvalue ) {
return 1000;
}
add_filter( 'pre_update_option_medium_size_h', 'themename_filter_medium_size_h' );
function themename_filter_medium_size_h( $newvalue ) {
return 1000;
}
add_filter( 'pre_update_option_large_size_w', 'themename_filter_large_size_w' );
function themename_filter_large_size_w( $newvalue ) {
return 1500;
}
add_filter( 'pre_update_option_large_size_h', 'themename_filter_large_size_h' );
function themename_filter_large_size_h( $newvalue ) {
return 1500;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment