Snippets: Add/Remove Image Sizes

// Add & remove image sizes from the "Image Sizes" panel
function my_image_sizes( $sizes ) {

    // Remove "blog_post_full" image size
    unset( $sizes['blog_post_full'] );

    // Add new image size "my_image_sizes"
    $sizes['my_image_size'] = array(
        'label'     => __( 'My Image Size', 'wpex' ), // Label
        'width'     => 'my_image_size_width', // id for theme_mod width
        'height'    => 'my_image_size_height', // id for theme_mod height
        'crop'      => 'my_image_size_crop', // id for theme_mod crop
    );

    // Return sizes
    return $sizes;

}
add_filter( 'wpex_image_sizes', 'my_image_sizes', 9999 );

Snippet Type: PHP

Posted Under: Core

All PHP snippets should be added via a child theme's functions.php file.