How to add relative path in wordpress editor


Here is the code for adding relative path inside editor

copy paste the below code in your functions.php file


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);
update_option('image_default_link_type','none');

Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.