Last active
April 9, 2016 06:36
-
-
Save zlove/799fb79d86008414d6168654db55a821 to your computer and use it in GitHub Desktop.
Fix srcset URLs at WP Engine
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
<?php | |
/** | |
* Change srcset URLs to https if the page is loaded via https | |
* Activate with: | |
* | |
* add_filter( 'wp_calculate_image_srcset', 'zbs_fix_srcset_for_https' ); | |
* | |
* @param array $sources array of sources used in srcset. | |
* @return array | |
*/ | |
function zbs_fix_srcset_for_https( $sources ) { | |
if ( is_ssl() ) { | |
foreach ( $sources as &$source ) { | |
$source['url'] = set_url_scheme( $source['url'], 'https' ); | |
} | |
} | |
return $sources; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the WP Plugin from @salcode here, but I just wanted a filter