Skip to content

Instantly share code, notes, and snippets.

@Debadge
Created February 17, 2016 14:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Debadge/84202bb6de3852f6642a to your computer and use it in GitHub Desktop.
Save Debadge/84202bb6de3852f6642a to your computer and use it in GitHub Desktop.
Fixes srcset URLs on WordPress Multisite installations when using Domain Mapping
// Fix the URLS generated by media srcset from WP 4.4+
//
// When viewing the srcset URLs for images on a 4.4+ WordPress installation,
// it was showing my multisite subdomain URL rather than the domain chosen during Domain Mapping
//
// Add to your functions.php and modify the URL fields
//
// See: https://make.wordpress.org/core/2015/11/10/responsive-images-in-wordpress-4-4/
function fix_multisite_srcset( $sources ){
foreach ( $sources as &$source ) {
$sources[ $source['value'] ][ 'url' ] = str_replace('http://OLD-URL', 'http://ACTUAL-URL', $sources[ $source['value'] ][ 'url' ]);
}
return $sources;
}
add_filter( 'wp_calculate_image_srcset', 'fix_multisite_srcset' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment