🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Disable WordPress default responsive image generation feature

Previously, I integrated Upyun acceleration for the website,using UPYun to accelerate your WordPress website, and today I encountered a bug. I addedDisable 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 addedsrcset="" 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 pluginDisable Responsive Images Complete

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step instead.

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about Website Building Coaching Service
🔒

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.

×
二维码

Scan to Follow