Cloudflare and WordPress multisite

Issue: Site uses Cloudflare and uses flexible SSL to serve pages. However, within WordPress, any http:// referenced sources are being referenced as http:// instead of https://

Solution 1: For the site in question, you can force resources to automatically upgrade. Put the following line in your .htaccess file:

Header always set Content-Security-Policy: upgrade-insecure-requests

An explanation of what that does is listed here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/upgrade-insecure-requests

Solution 2: Insert this script below your functions.php file in your child theme and they should load again (but note, updating the theme might break this and you will need to do it again):

 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' );

Credit:
http://docs.layerswp.com/doc/wordpress-images-dont-load-after-4-4-update-with-ssl-enabled/

Leave a Reply

Your email address will not be published. Required fields are marked *

*