Skip to content

Instantly share code, notes, and snippets.

@marianmirzacu
Forked from joemcgill/ssl_srcset.php
Created September 3, 2019 17:25
Show Gist options
  • Save marianmirzacu/16d81063084f9b0a1fab9f5e2be98eb1 to your computer and use it in GitHub Desktop.
Save marianmirzacu/16d81063084f9b0a1fab9f5e2be98eb1 to your computer and use it in GitHub Desktop.
Force WordPress `srcset` to HTTPS
/*
* Force URLs in srcset attributes into HTTPS scheme.
* This is particularly useful when you're running a Flexible SSL frontend like Cloudflare
*/
function ssl_srcset( $sources ) {
foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'], 'https' );
}
return $sources;
}
add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment