最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Can't locate custom image sizes defined by child theme

programmeradmin6浏览0评论

I'm developing a child theme (mms-child) based on a simple parent (mms – also my dev). I am quite used to the usual way of defining custom image sizes within functions.php as follows:

add_theme_support( 'post-thumbnails' );
  add_image_size( 'Size name', 2000, 9999 );

I have removed all instances of this in the child theme's functions file, and checked to make sure there is nothing like this in the parent theme either. So – I am expecting nothing in my list of thumbnail sizes other than the standard WordPress defualts.

But the media area of the WordPress settings tells me this:

The sizes listed below are the crop and resize formats defined by mms-child

I have been though all files in both themes and can find nothing that would define these image sizes. I don't need them. How can I locate this instruction and remove it?

I'm developing a child theme (mms-child) based on a simple parent (mms – also my dev). I am quite used to the usual way of defining custom image sizes within functions.php as follows:

add_theme_support( 'post-thumbnails' );
  add_image_size( 'Size name', 2000, 9999 );

I have removed all instances of this in the child theme's functions file, and checked to make sure there is nothing like this in the parent theme either. So – I am expecting nothing in my list of thumbnail sizes other than the standard WordPress defualts.

But the media area of the WordPress settings tells me this:

The sizes listed below are the crop and resize formats defined by mms-child

I have been though all files in both themes and can find nothing that would define these image sizes. I don't need them. How can I locate this instruction and remove it?

Share Improve this question asked Jul 30, 2020 at 10:31 mtmmtm 538 bronze badges 1
  • So you add an image size in the parent, but want to remove it in the child? How are you calling those functions? Is this on a hook? I strongly suspect the problem here is ordering, as well as not doing work on hooks. Am I right in thinking the code in your functions.php is just dumped in the root scope and not inside a function hooked to init or another action? – Tom J Nowell Commented Jul 30, 2020 at 10:53
Add a comment  | 

1 Answer 1

Reset to default 1

These images sizes are defined by WordPress, and were added in WordPress 5.3. The comments in the source code describe them like this:

These sizes are meant to enhance the way WordPress displays images on the front-end on larger, high-density devices. They make it possible to generate more suitable srcset and sizes attributes when the users upload large images.

The sizes can be changed or removed by themes and plugins but that is not recommended. The size "names" reflect the image dimensions, so changing the sizes would be quite misleading.

The "Image sizes are defined by the current theme" screen from your screenshot is not part of WordPress. It must be from a plugin that you're using that is not aware of these new sizes and is incorrectly attributing them to your theme. You would need to ask its developer why.

You can stop them being generated by adding this line to a Must Use plugin:

remove_action( 'plugins_loaded', '_wp_add_additional_image_sizes', 0 );

But you really shouldn't, as they were added for a good reason.

发布评论

评论列表(0)

  1. 暂无评论