Skip to content

Add/Remove Image Sizes

This example snippet can be used to add new image size options and tabs to the Image Sizes panel. This is useful if you are developing a third-party add-on for the theme.

If you are creating custom post types using our Post Types Unlimited plugin, the plugin will automatically add image size options for your post types (when enabled in the plugin settings), so you won’t need to use a snippet in that case.

/**
 * Add & remove image sizes from the Image Sizes panel.
 */
add_filter( 'wpex_image_sizes', function( array $sizes ): array {

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

    // Add new image size "my_image_sizes"
    $sizes['my_image_size'] = [
        'label' => esc_html__( 'My Image Size', 'wpex' ),
        'section' => 'other', // you could create your own tab instead - see below!
    ];

    return $sizes;

}, 99 );

/**
 * Add a new Tab to the Image Sizes panel.
 */
add_filter( 'wpex_image_sizes_tabs', function( array $tabs ): array {
    $tabs['my_custom_tab'] = esc_html__( 'My Custom Tab', 'total-child-theme' );
    return $tabs;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets
Back To Top