Last active
February 4, 2017 21:16
-
-
Save 5A5K1A/0ef3da57b72203bcef741fa40aa957c4 to your computer and use it in GitHub Desktop.
WordPress Make "in-site" URL's relative
This file contains hidden or 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/ | |
/* ------------------------------------ */ | |
add_filter('content_save_pre', function( $content ) { | |
$site_url = get_bloginfo('url'); | |
return str_replace(' href=\"'.$site_url, ' href=\"', str_replace(' src=\"'.$site_url, ' src=\"', $content)); | |
}, 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment