Created
December 20, 2012 07:19
-
-
Save bradyvercher/4343518 to your computer and use it in GitHub Desktop.
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/
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 | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For
thumbnail_crop
it should return a number:0
or1