The given page is a blog archive page that lists recent posts.
I want the featured image thumbnail on this page to load the same file size as it display (360px by 180px). I added the given code in functions.php of the theme, but it is still not working. It loads the old file of 408 x 204 size and display on new dimensions.
add_image_size('new-few-img', 360, 180,true);
the_post_thumbnail('new-few-img')
The new image size is registered, and the file appears in directory after regenerating the thumbnails. However, on front end it still loads the old dimensions and displays new dimensions (Forced by CSS).
I also tried using below line;
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'new-few-img' );
}
or
set_post_thumbnail_size(360,180,true);
or
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 360, 180, true );
}
Please help me resolve the issue.
CodePudding user response:
Add below code into you function.php file.
function register_new_thumbnail() {
add_theme_support( 'post-thumbnails' );
add_image_size('new-few-img', 360, 180,true);
}
add_action( 'after_setup_theme', 'register_new_thumbnail' );
Now your new thumbnail size is registered and will work on only new images. To crop your already used image you need a plugin which will help you to regenerate this thumbnail size.
- https://wordpress.org/plugins/regenerate-thumbnails/
- https://wordpress.org/plugins/regenerate-thumbnails-advanced/
I hope this may help your issue.