I want to add a custom image size to my child theme.

The base is the Penscratch theme, and it has it own image sizes defined:

function penscratch_setup() {

    /*  ...  */

    add_theme_support( 'post-thumbnails' );
    add_image_size( 'penscratch-featured', '400', '200', true );

    /*  ...  */

And if I made some changes here (base functions.php), everything work as it should, But the point is to make it done in child-Theme, I'm writing it the same way but for some reason it's not working:

add_action( 'after_setup_teme', 'add_custom_img_sizes');

function add_custom_img_sizes()
  add_theme_support( 'post-thumbnails' );
  add_image_size( 'category-thumbnail', '300', '200', true );

if I use then the 'category-thumbnail' in my template, it is displaying the full-sized image, not the cropped one, what is going wrong here?

  • You've misspelled the action name (you're missing the h in theme). You may also need to select the desired image size where you display the image in your template - normally you'd use something like the_post_thumbnail() to do so, however the "category-thumbnail" you mention isn't a part of WordPress core. You may need to address your question to the respective theme or plugin author. – bosco Apr 5 '17 at 22:08

After you add a new image size, you have to regenerate the images for that size. The Regenerate Thumbnails plugin comes in handy for this purpose.

| improve this answer | |
  • But when I'm making the changes to the base theme functions.php (penscratch theme), it's all working with just the page reload. So I guess it's not about some external plugin. – linearSpin Apr 5 '17 at 18:36
  • That's only possible if A) the base theme has the exact image size declaration "name" B) That image declaration declares the same "size" 3) the image physically exists of that size. penscratch-featured already existed when the image was uploaded. Durign the upload the image was resized to '400' x '200' and that image physically exists on the server. After you change the name or the size you'll need to reupload the image so that the new image size is regenerated or use the plugin to achieve it. – Shivanand Sharma Apr 5 '17 at 18:39
  • You're right, I was making the changes on an existing entry. Thanks for making this clear. – linearSpin Apr 5 '17 at 18:47

You have to add the handle name in your the post thumbnail

 the_post_thumbnail( 'category-thumbnail' );
| improve this answer | |
  • I wrote in my post, that I did this already. The last sentence of my question. – linearSpin Apr 5 '17 at 18:38

Now you can use the Command Line Interface (CLI) to regenerate the thumbnails using the wp media regenerate command:

wp media regenerate

Have a look at this page and follow the steps to install the wp command.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.