• Resolved kimpeartgratton

    (@kimpeartgratton)


    My brain is going to explode.

    When writing a new post, I want to be able to add to the media gallery ‘attachment display settings’ size options.

    I seem to have a default listing of Thumb, Med, Lge and Full. I want to create another size.

    I have tried myself and to no avail.

    If anyone can help, can you please tell me both what I need to write and what file I need to put it in. I have tried doing it myself and perhaps I’m not putting the script in the correct location.

    Many thanks

    Kim

Viewing 6 replies - 1 through 6 (of 6 total)
  • You need to register new custom image size.
    to do that, open your functions.php file (inside theme folder).

    Start by adding the support of post thumbnails (probably it is already supported, you maybe can skip this)

    add_theme_support( 'post-thumbnails' );

    Now you can use the functionality of registering additional image sizes you need like this:

    add_image_size( 'your-image-size-name', 120, 120, true ); // Hard crop
    add_image_size( 'your-image-size-name', 600, 400 ); // Soft crop

    You need to chose some name for that size (thumbnail, medium, large and full are already taken, write anything else), and to set size (width, height), if you add “true” WP will resize exactly to that dimensions, not proportional.

    To display that image size on your pages put this code in theme where you wish to display it:

    <?php the_post_thumbnail( 'your-image-size-name' ); ?>

    More info on:

    https://codex.www.ads-software.com/Function_Reference/add_image_size

    Thread Starter kimpeartgratton

    (@kimpeartgratton)

    Thank you for replying.

    I had read the wordpress section you linked to.

    I had already carried out the first two parts of the instructions, but I am lost of the last bit.

    When you say, “…put this code in the theme…” What do you mean? I want to be able to use the new sizes in blog posts, in the main content.

    Thanks again.

    Kim

    Hi Kim.,

    One you add the code in your theme. Add this plugin and regenerate new post thumbnails

    https://www.ads-software.com/plugins/regenerate-thumbnails

    Rajan V

    Thread Starter kimpeartgratton

    (@kimpeartgratton)

    This looks like what I want to do, but where oh where does it go?

    For Media Library Images (Admin)
    You can also make your custom sizes selectable from your WordPress admin. To do so, you have to use the image_size_names_choose hook to assign them a normal, human-readable name…

    add_filter( ‘image_size_names_choose’, ‘my_custom_sizes’ );

    function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
    ‘your-custom-size’ => __( ‘Your Custom Size Name’ ),
    ) );
    }

    Thread Starter kimpeartgratton

    (@kimpeartgratton)

    Ha ha – worked it out.

    So, for anyone else like me who wants to create new image sizes accessible from the Media Library:

    1. open your functions.php file (inside theme folder).

    2. Add theme support by pasting in:

    add_theme_support( 'post-thumbnails' );

    3. Add image sizes by pasting in:

    add_image_size( 'your-image-size-name', 120, 120, true ); // Hard crop
    add_image_size( 'your-image-size-name', 600, 400 ); // Soft crop

    4. Add to Media Library by pasting in:

    add_filter( 'image_size_names_choose', 'my_custom_sizes' );
    
    function my_custom_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'your-custom-size' => __('Your Custom Size Name'),
        ) );
    }

    Further reading:
    https://codex.www.ads-software.com/Function_Reference/add_image_size

    https://codex.www.ads-software.com/Plugin_API/Filter_Reference/image_size_names_choose

    Hi again.,

    Just put your theme function file (functions.php)

    add_theme_support( 'post-thumbnails' );
    add_image_size( 'your-image-size-name', 120, 120, true ); // Hard crop
    add_image_size( 'your-image-size-name', 600, 400 ); // Soft crop

    And Put this code where you want to display

    <?php the_post_thumbnail( 'your-image-size-name' ); ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘New Image Size’ is closed to new replies.