I
I
Ivan2021-06-16 22:07:02
WordPress
Ivan, 2021-06-16 22:07:02

How to set a new image size in WordPress?

Hello. You need to make a new image size for images-media files in WordPress. To make it appear on the menu.
The images will be 600 by 400. I write the code in "Theme Functions (functions.php)":

add_image_size( 'true-fullwd', 700 );
 
add_filter('image_size_names_choose', 'true_new_image_sizes');
 
function true_new_image_sizes($sizes) {
  $addsizes = array(
    "true-fullwd" => 'По ширине контента'
  );
  $newsizes = array_merge($sizes, $addsizes);
  return $newsizes;
}


But nothing is output. What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan Gerasimenko, 2021-06-17
@Kleindberg

Try this (instead of the code you wrote above):

add_theme_support( 'post-thumbnails' );
add_image_size( 'По ширине контента', 600, 400);

The add_image_size function takes the following parameters:
add_image_size( string $name, int $width, int $height, bool|array $crop = false )

name, width, height, hard crop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question