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

Disable WordPress's Default Feature of Generating Responsive Images

Previously, I integrated Upyun acceleration for the website,using Upyun to accelerate WordPress websites, as a result, I encountered a bug today. I added an image to the article aboutDisabling the New WordPress Editor, but the image didn't display. I saw that the image address in the editing interface was replaced with Upyun's, but the image didn't show on the front end. Checking the source code revealed there were still blog resource links.图片不显示
<p><img 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" /></p>
It can be seen that in the source code, the attributessrcset="" andsizes="" were inexplicably added, with the URL being the blog"s old address.After searching, I found out that it's because WordPress added the automatic responsive image setting 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's Default Feature of Generating Responsive Images

Just add the following content to the functions file and save it.
//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, the 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.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the 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 QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: