Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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="" /> will be converted to <img src="/image.gif" />
/* ---------------------------------------------------------------------------------- */
/* Convert absolute URLs in content to site relative ones
Inspired by
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;
/* ---------------------------------------------------------------------------------- */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.