Custom featured image size for thumbnails

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3957 Reply
    Ron
    Keymaster

    By default, you can choose from 2 image dimensions on which to show the excerpt’s thumbnail. One is the default 150×150, the other is 200×120. If you ever need to show the featured image thumbnails in a different dimension, you’ll need to add this code on your functions.php (on a child-theme) Replace ‘400’ and ‘220’ on the code with your desired dimensions.

    Only newly uploaded images will have the new exact size. You can use “Regenerate Thumbnails” plugin to apply the new size to older images. you can deactivate the plugin when done.

    The first function adds/registers the new image size. The second function displays the image on the excerpt replacing the default one.

    function add_new_thumb_size() {
         add_image_size( 'thumb-400x220', 400, 220, true );
    }
    add_action( 'after_setup_theme', 'add_new_thumb_size' );
    
    function display_new_thumbs() {
         $new_thumb = get_the_post_thumbnail( get_the_ID(), 'thumb-400x220' );
         return $new_thumb;
    }
    add_filter( 'frontier_excerpt_thumbnail', 'display_new_thumbs' );
Viewing 1 post (of 1 total)
Reply To: Custom featured image size for thumbnails
Your information: