Reputation: 77
I'm a total newbie to WordPress development and as far as it goes now, I understand that WP can create responsive images for me with a built in plugin since version 4.4.
In my project, I have two types of images. By types I mean their width. First one, the widest one is 633px (which is double the size for Retina displays), and I set it as a "Large" in settings -> media -> Large size. So, whenever I upload this one, it works just fine, cause the medium size is also preset.
The problem occurs with the second type of images. They are much narrower, and I need a preset of width for them, which I have to implement in functions.php. The width for "Large" is 612px, and for "Medium" 306px.
What kind of filter should I add in function.php to implement those new sizes in my admin Dashboard, so WP will spit out those photos in appropriate size?
Thanks ahead everyone!
PS - solution is found!
//Adding new img sizes
add_image_size( 'Portfolio-medium-wide', 633 );
add_image_size( 'Portfolio-large-wide', 1266 );
add_image_size( 'Portfolio-medium', 306 );
add_image_size( 'Portfolio-large', 612 );
add_image_size( 'Blog-medium', 469 );
add_image_size( 'Blog-large', 938 );
add_filter( 'image_size_names_choose','my_image_sizes' );
function my_image_sizes( $sizes ) {
return array_merge ( $sizes, array(
'Portfolio-medium-wide' => __('Portfolio Medium wide'),
'Portfolio-large-wide' => __('Portfolio Large wide'),
'Portfolio-medium' => __('Portfolio Medium'),
'Portfolio-large' => __('Portfolio Large'),
'Blog-medium' => __('Blog Medium'),
'Blog-large' => __('Blog large'),
));
}
Upvotes: 0
Views: 43
Reputation: 3673
Please use add_image_size function, please find the example below :
// defining size in functions.php
add_image_size( 'your_image_size', 370, 223,true);
//using the size in other pages
the_post_thumbnail('your_image_size');
Hope it helps
Upvotes: 1