additional image sizes
-
Hi,
for four days I have been looking for a way to add image sizes to wordpress.
wordpress comes with thumb, medium, large and full and I need four more to be able to select from, i.e. I need to be able to select from seven options when inserting an image into a page. To make it clear: I am not looking for support for a featured image and I do not want to use a plugin.I found the following code on the internet – the folloeing is meant for the
functions.php of the child theme and I inserted the added images:add_action( 'after_setup_theme', 'setup' ); function setup() { // ... add_theme_support( 'post-thumbnails' ); // This feature enables post-thumbnail support for a theme // To enable only for posts: //add_theme_support( 'post-thumbnails', array( 'post' ) ); // To enable only for posts and custom post types: //add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) ); // Register a new image size. // This means that WordPress will create a copy of the post image with the specified dimensions // when you upload a new image. Register as many as needed. // Adding custom image sizes (name, width, height, crop) add_image_size( 'smallest', 479, 157, true ); add_image_size( 'small', 768, 252, true ); add_image_size( 'small_medium', 981, 322, true ); add_image_size( 'normal_medium', 1536, 504, true ); add_image_size( 'better', 1962, 644, true ); add_image_size( 'normal_large', 2304, 768, true ); // ... } add_filter( 'image_size_names_choose', 'custom_image_sizes_choose' ); function custom_image_sizes_choose( $sizes ) { $custom_sizes = array( 'smallest' => 'Smallest', 'small' => 'Small', 'small_medium' => 'Small Medium', 'normal_medium' => 'Medium', 'better' => 'Better', 'normal_large' => 'Large' ); return array_merge( $sizes, $custom_sizes ); }PHP is completely new to me, but the the add_image part coincides with info from the wordpress codex and the add_filter is meant to let you select the image sizes in the wordpress gui.
But it is not working properly:
the upload directory contains the right image sizes but if I try to add an image to a page the amount of image sizes and their names are correct but some image sizes appear twice or more.As code for the loop i copied the index.php to my child theme folder and added
following line<?php if ( has_post_thumbnail()): the_post_thumbnail( 'smallest', array( 'class' => 'smallest' ) ); the_post_thumbnail( 'small', array( 'class' => 'small' ) ); the_post_thumbnail( 'small_medium', array( 'class' => 'small_medium' ) ); the_post_thumbnail( 'normal_medium', array( 'class' => 'normal_medium' ) ); the_post_thumbnail( 'better', array( 'class' => 'better' ) ); the_post_thumbnail( 'normal_large', array( 'class' => 'normal_large' ) ); endif; ?>I looked for following code snippet in my parent theme (Divi):
add_action( 'after_setup_theme'but as I could not find it i added it to my child theme.
I would be very glad for some help as the more I read in the internet the more confused I get.
thanks in advance
The topic ‘additional image sizes’ is closed to new replies.