• Firstly, sorry to create this as I’m aware there is an abundance of resources online about this very issue. It should be simple but for me and code don’t seem to get on at all, hence the need for a new post on the specific problem.

    In a nutshell, I installed new theme and installed child theme.
    I have an archive of custom featured images ready to upload but at present, the thumbnails displayed on the homepage of my site get cropped (left and right, thus chopping off text and the brand logo)

    I want to edit the featured image size on the homepage (and related posts widget) so that it scales in proportion, instead of cropping.

    From my research, this should be very straight-forward.

    a) Add a couple of lines of code to the functions.php in the child theme
    b) Install regenerate thumbnails plugin and activate it

    I’ve tried all this…it is driving me BONKERS!
    I’m clearly missing something but I can’t figure it out.

    Can somebody please help?

    I’ve attached a shot of the code as it currently is.
    The site is The Digital Crusader and you can see the problem with some of the images on the homepage where they are cropping instead of just scaling down (which they do successfully on the ‘Travel’ page of the site)

    If someone can help me out with concise instructions of how to finally fix this I would be sooo grateful!

    Thanks,

    CJ

    <?php 
    
    add_action( 'wp_enqueue_scripts', 'hellen_child_enqueue_styles');
    function hellen_child_enqueue_styles() {
    
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.min.css' );
    }
    
    if ( function_exists( 'add_theme_support' ) ) {
        add_theme_support( 'post-thumbnails' );
    
     }
     if ( function_exists( 'add_image_size' ) ) {
        add_image_size( 'my-new-thumb', 320, 180,false ); // 320 wide, 180 height, no crop, proportion scale
     }
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Moderator bcworkz

    (@bcworkz)

    The OP’s site appears to be self hosted. It’s hosted by a commercial host unrelated to wp.com AFAICT.

    When you add a custom size, to use it as a featured image, your template needs to specifically pass this size in a featured image call. For example the_post_thumbnail('my-new-thumb');. Unless you’ve changed your templates, they are still using the default “post-thumbnail” size. I’m not sure how the regenerate thumbnails plugin actually works. It may only resize “post-thumbnail” sized images. IDK, you can check you image files to see what has changed.

    If the 320×180 size is what you would like the default featured image size to be and you want to avoid editing your templates, use set_post_thumbnail_size() instead of add_image_size(). This will make the “post-thumbnail” size 320×180. When your template calls something like the_post_thumbnail() with no parameters, it’ll use that size.

    You do need to set the size after your parent theme does or else the size will be overridden. assuming your code is in a child theme, its code executes first, so you would need to set the size in a callback for the ‘after_setup_theme’ action or later. It’s also possible your theme uses its own special featured image size, in which case the name would be passed in featured image calls like the_post_thumbnail('themes-special-size');. If so, either set the size for that name or edit the function calls.

    Thread Starter digicruz

    (@digicruz)

    Hey folks, I managed to fix this issue after contacting the theme designer.
    He had specific names for the different thumbnails in the theme and so it took a little bit of insider info to get the job done!
    Thanks for the replies anyhow!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Featured Image Size in Child Theme’ is closed to new replies.