Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#39562 new defect (bug)

Responsive images: Changing upload path for new attachments will cause srcset path bug

Reported by: zairwolf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: General Keywords: reporter-feedback
Focuses: Cc:


for old attachments I used define( 'UPLOADS', 'wp-content/uploads_1' );

for new ones I used define( 'UPLOADS', 'wp-content/uploads_2' );

but when I visit old posts, the attachments' srcset path became uploads_2 while not uploads_1. It caused 404.

in wp-includes/media.php -> function wp_make_content_images_responsive() it uses the current upload path setting to generate all srcset, which is not right for old attachments.

Change History (5)

#1 @joemcgill
4 years ago

  • Keywords reporter-feedback added

Hi @zairwolf,

Thanks for the report. I'm interested in what method you're using to change the value of the UPLOADS constant based on the age of attachments. You may need to implement a similar workaround for srcset.

#2 @zairwolf
4 years ago

@joemcgill Thanks for fast reply. Yes you are right. We changed the upload folder to a new volume after the old disc is full.

I turned off responsive images so far based on


However, I think this is not the ideal way to handle it. Hope there will be a compatibility in future with this situation for srcset :)

#3 @joemcgill
4 years ago

Hi @zairwolf,

Do you have some logic that handles this for src when images are dynamically generated on the front end of your site (e.g., for featured images)? I'd like to see a specific example of what you're doing if you don't mind sharing.

#4 @zairwolf
4 years ago


src isn't generated dynamically. WP reads the attachment's absolute path from database in wp_get_attachment_url(). Even I changed the upload path for future, the old ones are fine. Please tell me if I am wrong.

So far as I checked, for existing imags, only srcset is generated dynamically.

#5 @joemcgill
4 years ago

For images that are contained in post content, the src is not generated dynamically. But in the src is dynamic for image previews in the media library and for images generated dynamically on the front end (e.g., post_thumbnails). In those cases, wp_get_attachment_url() useswp_get_upload_dir() to create the URL path.

Note: See TracTickets for help on using tickets.