Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress: Filter default image sizes on read to set custom sizes in a theme. Based on approach by Tammy Hart: http://10up.com/blog/2012/12/enforcing-wordpress-image-sizes-within-your-theme/
<?php
add_filter( 'pre_option_thumbnail_crop', 'themename_default_image_options' );
add_filter( 'pre_option_thumbnail_size_h', 'themename_default_image_options' );
add_filter( 'pre_option_thumbnail_size_w', 'themename_default_image_options' );
add_filter( 'pre_option_medium_size_h', 'themename_default_image_options' );
add_filter( 'pre_option_medium_size_w', 'themename_default_image_options' );
add_filter( 'pre_option_large_size_h', 'themename_default_image_options' );
add_filter( 'pre_option_large_size_w', 'themename_default_image_options' );
function themename_default_image_options( $value ) {
$option = str_replace( 'pre_option_', '', current_filter() );
switch ( $option ) {
case 'thumbnail_size_h' :
case 'thumbnail_size_w' :
$value = 180;
break;
case 'thumbnail_crop' :
$value = true;
break;
case 'medium_size_h' :
case 'medium_size_w' :
$value = 390;
break;
case 'large_size_h' :
case 'large_size_w' :
$value = 660;
break;
}
return $value;
}
@mems

This comment has been minimized.

Copy link

mems commented Sep 16, 2015

For thumbnail_crop it should return a number: 0 or 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.