Change Default Media Settings on Theme Activation
Let’s face it, if you’re a developer you want to make things as simple as possible for your clients. One way to do this is to set the default media sizes when your theme is activated. Your users should never need to try to figure out the width of the content area. They shouldn’t have find where the default settings are located. They shouldn’t have to worry about any of that. When they upload an image or use an embed code, the correct sizes should already be set. Here’s how you can do that for them.
// Reset default media sizes
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ){
global $wpdb;
$wpdb->query("UPDATE $wpdb->options SET option_value='200' WHERE option_name='thumbnail_size_w'");
$wpdb->query("UPDATE $wpdb->options SET option_value='200' WHERE option_name='thumbnail_size_h'");
$wpdb->query("UPDATE $wpdb->options SET option_value='1' WHERE option_name='thumbnail_crop'");
$wpdb->query("UPDATE $wpdb->options SET option_value='400' WHERE option_name='medium_size_w'");
$wpdb->query("UPDATE $wpdb->options SET option_value='400' WHERE option_name='medium_size_h'");
$wpdb->query("UPDATE $wpdb->options SET option_value='800' WHERE option_name='large_size_w'");
$wpdb->query("UPDATE $wpdb->options SET option_value='800' WHERE option_name='large_size_h'");
$wpdb->query("UPDATE $wpdb->options SET option_value='800' WHERE option_name='embed_size_w'");
$wpdb->query("UPDATE $wpdb->options SET option_value='0' WHERE option_name='embed_size_h'");
$wpdb->query("UPDATE $wpdb->options SET option_value='1' WHERE option_name='embed_autourls'");
}
This piece of code goes in the functions.php file of the theme. When the theme is activated, it sets all the default media sizes available on the Settings > Media page. Feel free to remove any lines that you don’t need. Then change the remaining values to fit the size of your theme and you’re ready to go!
I’ve looked before how to do something like this, so it’s nice to find it now.
In the past I’ve set the embed size for video using the following code. I wonder if there is something similar for the default image sized.
function themeit_embed_defaults( $embed_size ) {
$embed_size['width'] = 550;
$embed_size['height'] = 400;
return $embed_size;
}
add_filter( ‘embed_defaults’, ‘themeit_embed_defaults’ );
Interesting… Does the method you mention allow the user to override the embed sizes set by the theme?
I don’t think so, but I also don’t think it sets the values in the admin of the theme either. I’ll have to check on this.