Featured-image crop

Hello,

I’m here again asking for help. i had to crop the featured images from ‘top left’, and not ‘center center’. My code worked well, but stopped working suddently. Here is the code :


function modify_slider_image_size(){

    add_image_size( 'activello-featured', 1170, 550, array( 'left', 'top' ) );

    add_image_size( 'activello-slider', 1920, 550, array( 'left', 'top' ) );

    add_image_size( 'activello-thumbnail', 330, 220, array( 'left', 'top' ) );

    add_image_size( 'activello-medium', 640, 480, array( 'left', 'top' ) );

    /*left in x axis, top in y axis*/

}

add_action( 'init', 'modify_slider_image_size', 10 );

Obviously, it is in the functions.php of my child theme.

Thanks in advance

Hi @abdelhaksam,

I hope you are well today and thank you for your question.

Try using the below code instead.



function modify_slider_image_size(){

    add_image_size( 'activello-featured', 1170, 550, array( 'left', 'top' ) );

    add_image_size( 'activello-slider', 1920, 550, array( 'left', 'top' ) );

    add_image_size( 'activello-thumbnail', 330, 220, array( 'left', 'top' ) );

    add_image_size( 'activello-medium', 640, 480, array( 'left', 'top' ) );

    /*left in x axis, top in y axis*/

}

add_action( 'init', 'modify_slider_image_size', 99 );

Also use the following plugin to regenerate thumbnails images.

Best Regards,
Movin

Hello,

It still doesn’t work, should i increase the number again ?

Yes you can try doing that.

I wrote 1000, but nothing happenned :confused:

If the code was working fine for you then do you remember what you have changes on your site that caused it not to work.

Could you please share me your child theme where you have added this code so that i can troubleshoot it on my test site?

I did not exactly notice when it actually happened, i think it might be when i moved to the server from my localhost.

The child theme is attached. Thank you.

I modified the code in your shared child theme files content-archives.php and content-single.php as following to make it work and regenerate thumbnails using the plugin Regenerate Thumbnails – WordPress plugin | WordPress.org

Before :


<?php the_post_thumbnail( 'full', array( 'class' => 'single-featured' )); ?>

After :


<?php the_post_thumbnail( 'activello-featured', array( 'class' => 'single-featured' )); ?>

Please make the same changes in your child theme to make it work.

Hello,

Thank you for your reactivity,

That’s not exactly what i wanted (the problem occurs in the home page, not the archive tag page), but thank you anyway. :smiley:

Regards,

It is working fine on all pages on my test site.

If it is still not working for you then could you please share me your site URL where it’s happening so that i can troubleshoot it?