Skip to content

Instantly share code, notes, and snippets.

@mattfarina
Created December 27, 2011 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattfarina/1523736 to your computer and use it in GitHub Desktop.
Save mattfarina/1523736 to your computer and use it in GitHub Desktop.
Protocol relative image paths in Drupal 7
<?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