Title: Plugin does not work with custom image sizes in theme
Last modified: February 21, 2019

---

# Plugin does not work with custom image sizes in theme

 *  Resolved [zachary.lv](https://wordpress.org/support/users/zacharylv/)
 * (@zacharylv)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/)
 * I was testing using this plugin with a custom theme, but could not get the img
   output to include the wpsmartcrop* classes, or data-smart-crop-focus attributes.
 * I dug into the plugin code and added some error logging to monitor what data 
   was being passed around when the_content filter added by the plugin executes.
 * From what I’ve seen it appears the plugin won’t work with themes that define 
   custom sizes. WP_Smart_Crop->is_image_size_cropped() returns true if WP_Smart_Crop-
   >get_image_sizes() finds additional images sizes registered in WordPress. When
   this occurs WP_Smart_Crop->get_smartcrop_focus_attr() returns no data, which 
   means WP_Smart_Crop->make_new_content_img_tag() returns the original img tag 
   unaltered.
 * I edited the function WP_Smart_Crop->is_image_size_cropped() to always return
   false, and then the plugin started working, and I was seeing the focus point 
   data behave as expected. Is there a reason the WP_Smart_Crop->is_image_size_cropped()
   function exists, and is there some way it can be fixed so this will work with
   themes that define custom image sizes?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [zachary.lv](https://wordpress.org/support/users/zacharylv/)
 * (@zacharylv)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11237472)
 * I was doing some additional testing with one of WordPress’ default themes and
   realized that it’s not custom image sizes that prevent the plugin data from being
   output, it’s inserting images from an image that uses a hard-crop that prevents
   output of the data.
 * I take it this is on the assumption that images with a hard crop don’t account
   for extra space necessary to adjust the focal point.
 *  Thread Starter [zachary.lv](https://wordpress.org/support/users/zacharylv/)
 * (@zacharylv)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11247817)
 * Turns out I was right the first time. There is an issue with this plugin working
   with themes and plugins that define custom image sizes. It also prevents the 
   plugin from working when templates make a call for images with the post-thumbnail
   size defined by WordPress.
 * The normal procedure for adding custom images sizes and setting a custom post
   thumbnail size use add_image_size() which registers the custom size in the $_wp_additional_image_sizes
   global variable. However, although the WP SmartCrop loads this variable when 
   it checks for available image sizes, it does not use the values stored in this
   variable to confirm if an image should output the wpsmartcrop classes and data
   attribute.
 * Instead the plugin pulls the dimensions and crop value for registered image sizes
   from the options table in the database on lines 598-602 in wp-smartcrop.php. 
   These options only exist for the default image sizes in WordPress (thumbnail,
   medium, medium-large, large). Because of this SmartCrop will not work for any
   custom image sizes, or for the post-thumbnail size defined in WordPress, as that
   also does not record dimensions in the database.
 * I was able to solve this problem on my custom theme by calling update_option(
   $my_size . ‘_size_w’, $width ); etc for all my custom defined image sizes after
   adding them with add_image_size() and for the post-thumbnail size. This makes
   the option data available when SmartCrop tries to verify an image size will support
   a focus point. This data is irrelevant to WordPress core and my custom theme,
   however, so it’s just a bandaid in a sense.
 * The plugin should be updated so it can work properly with custom image sizes.
 * A bit of a headache sorting this out, but otherwise a cool plugin when it’s working.
 *  Plugin Author [Bytes.co](https://wordpress.org/support/users/burlingtonbytes/)
 * (@burlingtonbytes)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11288096)
 * Hello zachary.lv,
 * We’ve updated the plugin to version 2.0.2, which should resolve this issue.
 * Let us know if you continue to experience any difficulties.
 * Best,
    Bytes.co
 *  [Storm Rockwell](https://wordpress.org/support/users/stormrockwell/)
 * (@stormrockwell)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11331761)
 * Ignore this
 *  [Rachelle Wise](https://wordpress.org/support/users/chellechan/)
 * (@chellechan)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11380246)
 * [@zacharylv](https://wordpress.org/support/users/zacharylv/) Did the 2.0.2 version
   resolve your issue? I just ran into this issue on a site and am trying to find
   a solution. 2.0.2 doesn’t fix it for me.
 * I’m pulling in an image with wp_get_attachment_image — WP Smartcrop works fine
   if the function calls for default “medium” size, but if I switch to a custom 
   size, WP Smartcrop doesn’t run on it. 🤔
 *  [Rachelle Wise](https://wordpress.org/support/users/chellechan/)
 * (@chellechan)
 * [7 years ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11384122)
 * [@burlingtonbytes](https://wordpress.org/support/users/burlingtonbytes/) Do you
   have any ideas regarding the above message? I would be ever so grateful to get
   this working. My last bug on a site build! haha
    -  This reply was modified 7 years ago by [Rachelle Wise](https://wordpress.org/support/users/chellechan/).
 *  Plugin Author [Bytes.co](https://wordpress.org/support/users/burlingtonbytes/)
 * (@burlingtonbytes)
 * [7 years ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11384666)
 * Hi [@chellechan](https://wordpress.org/support/users/chellechan/),
 * We’re still working on fix for this. Earlier in this thread [@zacharylv](https://wordpress.org/support/users/zacharylv/)
   documented a workaround for the issue, by calling update_option to register your
   custom sizes in wp_options. I’d recommend giving that a shot until we can get
   a patch for this tested and released.
 * Thank you [@zacharylv](https://wordpress.org/support/users/zacharylv/) for the
   work you put into troubleshooting this!
 *  [Rachelle Wise](https://wordpress.org/support/users/chellechan/)
 * (@chellechan)
 * [7 years ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11385524)
 * Ah! Totally overlooked that. Thank you, [@burlingtonbytes](https://wordpress.org/support/users/burlingtonbytes/).
   Will do. And thanks so much for creating this great plugin and keeping it up —
   discovering it has been a major game-changer for me. 🙌

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Plugin does not work with custom image sizes in theme’ is closed to new
replies.

 * ![](https://ps.w.org/wp-smartcrop/assets/icon-256x256.png?rev=1371575)
 * [WP SmartCrop](https://wordpress.org/plugins/wp-smartcrop/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-smartcrop/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-smartcrop/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-smartcrop/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-smartcrop/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-smartcrop/reviews/)

## Tags

 * [Custom Themes](https://wordpress.org/support/topic-tag/custom-themes/)

 * 8 replies
 * 4 participants
 * Last reply from: [Rachelle Wise](https://wordpress.org/support/users/chellechan/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/plugin-does-not-work-with-custom-image-sizes-in-theme/#post-11385524)
 * Status: resolved