Skip to content

Instantly share code, notes, and snippets.

@tlongren
Created December 22, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlongren/46fffa5bf14720778fdb to your computer and use it in GitHub Desktop.
Save tlongren/46fffa5bf14720778fdb to your computer and use it in GitHub Desktop.
Convert Images to be Relative
function image_to_relative($html, $id, $caption, $title, $align, $url, $size, $alt) {
$sp = strpos($html,"src=") + 5;
$ep = strpos($html,"\"",$sp);
$imageurl = substr($html,$sp,$ep-$sp);
$relativeurl = str_replace("http://","",$imageurl);
$sp = strpos($relativeurl,"/");
$relativeurl = substr($relativeurl,$sp);
$html = str_replace($imageurl,$relativeurl,$html);
return $html;
}
add_filter('image_send_to_editor','image_to_relative',5,8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment