Previously, I integrated Upyun acceleration for the website,
using UPYun to accelerate your WordPress website, and today I encountered a bug. I added
Disable WordPress New Editoran image to the article, but the image did not display. I saw that the image address in the editing interface was replaced with Upyun's, but the image did not show on the frontend. Checking the source code revealed that there were still old blog resource links.

src="https://blog.naibabiji.com/wp-content/uploads/2019/04/naibabiji.com_2019-05-06_14-49-40.jpg" alt="禁用Wordpress新版编辑器" width="600" height="377" class="aligncenter size-full wp-image-744" srcset="https://blog.naibabiji.com/wp-content/uploads/2019/04/naibabiji.com_2019-05-06_14-49-40.jpg 600w, https://blog.naibabiji.com/wp-content/uploads/2019/04/naibabiji.com_2019-05-06_14-49-40-150x94.jpg 150w" sizes="(max-width: 600px) 100vw, 600px" />
It can be seen that in the source code, there are inexplicably added
srcset="" andsizes="" two attributes, with URLs being the old blog addresses.After searching, I found that it's because WordPress added the automatic responsive image feature after version 4.4, and the Upyun plugin apparently cannot replace this part yet. So we need to disable this automatic responsive image attribute code.
Disable WordPress default responsive image generation feature
Simply add the following content to the functions file and save.
//disable srcset on images
function disable_srcset( $sources ) {
return false;
}
add_filter( 'wp_calculate_image_srcset', 'disable_srcset' );Additionally, Naiba also tested that as long as the image does not contain this class attribute, responsive image attributes will not be generated either. class="aligncenter size-full wp-image-744" Also, there is a corresponding WordPress plugin
Disable Responsive Images Complete
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.