Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created February 26, 2017 22:11
Show Gist options
  • Save wpexplorer/e3e7c4abd2937bb424ad8f485af4bf3d to your computer and use it in GitHub Desktop.
Save wpexplorer/e3e7c4abd2937bb424ad8f485af4bf3d to your computer and use it in GitHub Desktop.
function wpex_honor_ssl_for_attachments( $url ) {
if ( is_ssl() ) {
$upload_info = wp_upload_dir();
if ( isset( $upload_info[ 'baseurl' ] ) && strpos( $upload_info[ 'baseurl' ], 'https' ) ) {
$http = site_url( FALSE, 'http' );
$https = site_url( FALSE, 'https' );
return str_replace( $http, $https, $url );
}
}
return $url;
}
add_filter( 'wp_get_attachment_url', 'wpex_honor_ssl_for_attachments' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment