Skip to content

Instantly share code, notes, and snippets.

@andyknapp
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyknapp/11195654 to your computer and use it in GitHub Desktop.
Save andyknapp/11195654 to your computer and use it in GitHub Desktop.
Register image sizes - WordPress
/* register additional image sizes */
function ak_insert_custom_image_sizes( $image_sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $image_sizes;
// add all the custom sizes to the built-in sizes
foreach ( $_wp_additional_image_sizes as $id => $data ) {
// take the size ID (e.g., 'my-name'), replace hyphens with spaces,
// and capitalise the first letter of each word
if ( !isset($image_sizes[$id]) )
$image_sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
}
return $image_sizes;
}
function ak_custom_image_setup () {
add_theme_support( 'post-thumbnails' );
add_image_size('slider-big', 787, 325, TRUE);
add_image_size('slider-small', 587, 242, TRUE);
add_image_size('header-big', 787, 200, TRUE);
add_image_size('header-small', 500, 200, TRUE);
add_image_size('gallery-small', 425);
add_filter( 'image_size_names_choose', 'ak_insert_custom_image_sizes' );
}
add_action( 'after_setup_theme', 'ak_custom_image_setup' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment