• Hey,

    i tried to add a custom image size. The Goal is to add a custom square image within the post with a custom template .I have read the functions for this and wrote for testing:

    //Image Size
    add_image_size( 'custom-size', 220, 180, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
    
    add_filter( 'image_size_names_choose', 'category-thumb' );
    
    function my_custom_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'your-custom-size' => __( 'Your Custom Size Name' ),
        ) );
    }

    The Result of this is that all standard sizes went away. What am i doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • If you don’t need people to be able to choose your custom size from the Media Library, and just need it for templates, then only the ‘add_image_size’ line is necessary.

    If you do, change:
    add_filter( 'image_size_names_choose', 'category-thumb' );
    to:
    add_filter( 'image_size_names_choose', 'my_custom_sizes' );

    Hi Deexgnome,

    I would like to let you know that you will need to just add only one line with unique thumnail-size name (like : sidebar-thumb,homepage-thumb,singlepost-thumb) for one thumbnail size and it may be more if you require more thumbnail size.

    add_image_size( ‘sidebar-thumb’, 120, 120, true ); // Hard Crop Mode
    add_image_size( ‘homepage-thumb’, 220, 180 ); // Soft Crop Mode
    add_image_size( ‘singlepost-thumb’, 590, 9999 ); // Unlimited Height Mode

    you will need to pass your thumbnail size name to post thumnail function to get the image your size.

    the_post_thumbnail( ‘your-specified-image-size’ );

    Thread Starter Theunknown1

    (@deexgnome)

    Thanks a lot that worked 🙂

    But i got a further issue. I used the Thumbnails within a plugin with a own CSS Style, that is working fine example: https://on.gnetwork.eu/Zc.jpg

    But if i now add a caption to the thumbnail, this is not working. I see a code instead of the label

    Image: https://on.gnetwork.eu/bd.jpg

    I don’t know if this is a related bug because of the new sizes, or a general bug that i can’t use captions within a plugin.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Image Size, i'm doing it wrong’ is closed to new replies.