Get WordPress to URL-Encode Image uploads

WordPress 4.4 appears to have a bug where images added through the editor in Visual Composer (TinyMCE?) are not URL-encoded. This cause errors on image paths with spaces when WP automatically generates the srcset attribute.

Eg:

Should be:

Due to plugin/theme incompatibilities I can’t upgrade to a newer version of WP (yet) but was wondering if anybody has run into this before and knows a fix. The fix has to happen in PHP when the page is saved because otherwise WordPress generates a srcset attribute which is also invalid, eg:

Spaces in srcset cannot be “safely” ignored by the browser like in src because spaces are a delimiter between URLs and sizes.

Read more here: Get WordPress to URL-Encode Image uploads

Leave a Reply

Your email address will not be published. Required fields are marked *