Created
December 27, 2011 14:00
-
-
Save mattfarina/1523736 to your computer and use it in GitHub Desktop.
Protocol relative image paths in Drupal 7
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 | |
/** | |
* Implementation of hook_preprocess_image(). | |
* | |
* Make images that use a full url be protocol relative. | |
*/ | |
function custom_preprocess_image(&$variables) { | |
// If the image URL starts with a protocol remove it and use a | |
// relative protocol. | |
$scheme = file_uri_scheme($variables['path']); | |
$protocols = array('http', 'https'); | |
if ($scheme && in_array($scheme, $protocols)) { | |
$variables['path'] = '//' . file_uri_target($variables['path']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment