Created
February 17, 2016 14:07
-
-
Save Debadge/84202bb6de3852f6642a to your computer and use it in GitHub Desktop.
Fixes srcset URLs on WordPress Multisite installations when using Domain Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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