How do stop image cropping in the Divi Gallery module?

, ,

Recently in one of the DIVI related Facebook groups that I am a member of, one of the group wanted to know how to stop thumbnail images from being cropped in a Divi Gallery, so here’s what you need to do.

Add the the following code to the functions.php file of your child theme:


// Begin remove Divi Gallery Module image crop
function pa_gallery_image_width( $size ) {
return 9999;
}
function pa_gallery_image_height( $size ) {
return 9999;
}
add_filter( 'et_pb_gallery_image_width', 'pa_gallery_image_width' );
add_filter( 'et_pb_gallery_image_height', 'pa_gallery_image_height' );
// End remove Divi Gallery Module image crop

 

You should not add this code to the functions.php file of your main theme as every-time you update the theme you will have to remember re-add the code in, whereas with a child theme the theme code will be kept.

 

There is also code that you can use to stop blog featured images and portfolio featured images from being cropped and I will share these solutions in future blog posts.

2 thoughts on “How do stop image cropping in the Divi Gallery module?”

  1. Hi

    I have downloaded, installed and activated the Pee-Aye Creative free child theme and also pasted the code above in the functions.php in the child theme but it makes no differences to the cropping of my images on my gallery. Please refer to the wedding images on our website (https://hammesphotography.co.za) under the Portfolio and Weddings.

    Any idea why the code is not being applied? Below is the all the code that is in the functions.php file:

    <?php
    /**
    * Free Divi Child Theme by Pee-Aye Creative
    * Functions.php
    *
    * ===== NOTES ==================================================================
    *
    * New to Divi? Take our full Divi course: https://www.peeayecreative.com/product/beyond-the-builder-the-ultimate-divi-website-course/
    *
    * Learn cool tricks and features with our Divi tutorials: https://www.peeayecreative.com/blog/
    *
    * Discover our premium Divi products: https://www.peeayecreative.com/shop/
    *
    * =============================================================================== */

    function divichild_enqueue_scripts() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_script( 'custom-js', get_stylesheet_directory_uri() . '/js/scripts.js', array( 'jquery' ));
    }
    add_action( 'wp_enqueue_scripts', 'divichild_enqueue_scripts' );

    //you can add custom functions below this line:

    // Begin remove Divi Blog Module featured image crop
    function pa_blog_image_width($width) {
    return '9999';
    }
    function pa_blog_image_height($height) {
    return '9999';
    }
    add_filter( 'et_pb_blog_image_width', 'pa_blog_image_width' );
    add_filter( 'et_pb_blog_image_height', 'pa_blog_image_height' );
    // End remove Divi Blog Module featured image crop

    // Begin remove Divi Portfolio and Filterable Portfolio featured image crop
    function pa_portfolio_image_width($width) {
    return '9999';
    }
    function pa_portfolio_image_height($height) {
    return '9999';
    }
    add_filter( 'et_pb_portfolio_image_width', 'pa_portfolio_image_width' );
    add_filter( 'et_pb_portfolio_image_height', 'pa_portfolio_image_height' );
    // End remove Divi Portfolio and Filterable Portfolio featured image crop

    Regards
    Johan

    South Africa

    Reply
    • Hi Johan,

      Thanks for getting in touch.

      The code on this page was actually incorrect and should have read:

      // Begin remove Divi Gallery Module image crop
      function pa_gallery_image_width( $size ) {
      return 9999;
      }
      function pa_gallery_image_height( $size ) {
      return 9999;
      }
      add_filter( 'et_pb_gallery_image_width', 'pa_gallery_image_width' );
      add_filter( 'et_pb_gallery_image_height', 'pa_gallery_image_height' );
      // End remove Divi Gallery Module image crop

      If you try adding this to the functions.php file of your child theme it should work.

      I have updated the original blog article so that it contains the correct code.

      Thanks

      Lucy

      Reply

Leave a comment