Last active
December 22, 2015 05:09
-
-
Save iagdotme/6422105 to your computer and use it in GitHub Desktop.
Convert absolute URLs in blog and page content to site relative ones. The conversion happens when you save or publish content.
For example <img src="http://www.yoursite.com/image.gif" /> will be converted to <img src="/image.gif" />
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 | |
/* ---------------------------------------------------------------------------------- */ | |
/* Convert absolute URLs in content to site relative ones | |
Inspired by http://thisismyurl.com/6166/replace-wordpress-static-urls-dynamic-urls/ | |
*/ | |
function sp_clean_static_url($content) { | |
$thisURL = get_bloginfo('url'); | |
$stuff = str_replace(' src=\"'.$thisURL, ' src=\"', $content ); | |
$stuff = str_replace(' href=\"'.$thisURL, ' href=\"', $stuff ); | |
return $stuff; | |
} | |
add_filter('content_save_pre','sp_clean_static_url','99'); | |
/* ---------------------------------------------------------------------------------- */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment