Created
December 22, 2014 12:22
-
-
Save tlongren/46fffa5bf14720778fdb to your computer and use it in GitHub Desktop.
Convert Images to be Relative
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
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