Skip to content

Instantly share code, notes, and snippets.

@zlove
Last active April 9, 2016 06:36
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 zlove/799fb79d86008414d6168654db55a821 to your computer and use it in GitHub Desktop.
Save zlove/799fb79d86008414d6168654db55a821 to your computer and use it in GitHub Desktop.
Fix srcset URLs at WP Engine
<?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;
}
@zlove
Copy link
Author

zlove commented Apr 9, 2016

Based on the WP Plugin from @salcode here, but I just wanted a filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment