Skip to content

Instantly share code, notes, and snippets.

@leepowers
Last active February 12, 2020 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leepowers/9862956 to your computer and use it in GitHub Desktop.
Save leepowers/9862956 to your computer and use it in GitHub Desktop.
Fix `clean_url` entities
<?php
/**
* Fix esc_url/clean_url. Instead of escaping `&` to numeric character entities, this filter encodes them as `&amp;`
* Some browsers (such as Android Chrome 33.0.1750.170) don't parse `&#038;` correctly inside `<script src="..."></script>` tags.
* Such browsers leave out or otherwise mangle query string parameters.
* For instance, for a URL like `//maps.googleapis.com/maps/api/js?key=xxxx&#038;sensor=false` the `sensor` parameter is not being sent to the server correctly.
*/
function lpowers_fix_url_entities($url, $original_url, $_context) {
$bad_entity = "&#038;";
$good_entity = "&amp;";
$url = str_replace($bad_entity, $good_entity, $url);
return $url;
}
add_filter("clean_url", "lpowers_fix_url_entities", 99, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment