• Resolved gmcoffi

    (@gmcoffi)


    Hello,

    I am using ACF Frontend in combination with your plugin/addon

    Question: With your plugin, how do I crop and set the featured image ratio?

    Great plugin by the way!

    Thanks in advance,
    — GM

    • This topic was modified 2 years, 8 months ago by gmcoffi.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author joppuyo

    (@joppuyo)

    Hey,

    This is not a feature built into the plugin but you can accomplish this with the following code:

    add_action('acf/save_post', function ($post_id) {
        
        $value = get_field('my_crop_image_field', $post_id);
        
        if ($value) {
            if (!is_numeric($value)) {
                $value = $value['ID'];
            }
            update_post_meta($post_id, '_thumbnail_id', $value);
            
        // Check if field is here AND empty
        } elseif($value === false) {
            delete_post_meta($post_id, '_thumbnail_id');
        }
        
    }, 11);

    Just make sure you update my_crop_image_field so it’s the actual name of the ACF crop image field.

    The code is originally from this thread.

    Thread Starter gmcoffi

    (@gmcoffi)

    Hello,

    Do I add the code in my functions.php file? If not where do I add the code you provided?

    You also said “Just make sure you update my_crop_image_field” What does it mean? I update it with what information? Where do I find my_crop_image_field?

    Thanks in advance,
    — GM

    Plugin Author joppuyo

    (@joppuyo)

    Hey, my_crop_image_field should be the name of the field that you have specified when creating the field.

    The code should go to theme functions.php or a custom plugin.

    Using this plugin assumes the user has certain level of coding experience. If using custom code is too difficult, I encourage hiring someone with coding experience to create a custom solution that works in the specific case.

    • This reply was modified 2 years, 7 months ago by joppuyo.
    • This reply was modified 2 years, 7 months ago by joppuyo.
    Thread Starter gmcoffi

    (@gmcoffi)

    Thank you so much!

    Plugin Author joppuyo

    (@joppuyo)

    Since this issue is solved, I’m going to close this thread.

    Thread Starter gmcoffi

    (@gmcoffi)

    Actually I’ve tried your code but I don’t see any change. Thanks for your patience. Maybe I need to hire a developer to see if my theme could be the problem.
    It generate a feature image when a video is embedded on a post.

    • This reply was modified 2 years, 7 months ago by gmcoffi.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Crop Featured Image’ is closed to new replies.