Last active
January 3, 2016 12:29
-
-
Save 0x46616c6b/8463156 to your computer and use it in GitHub Desktop.
Simple way to return relative urls with wordpress built in wp_enqueue_* function. Good for caching!
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 | |
/** | |
* cut the base url from the assets | |
* | |
* @param $src | |
* @param $handle | |
* @return mixed | |
*/ | |
function make_urls_relative($src, $handle) | |
{ | |
if (strpos(get_bloginfo('url'), 'https') === 0) { | |
$search = array( | |
get_bloginfo('url'), | |
str_replace('https', 'http', get_bloginfo('url')) | |
); | |
} else { | |
$search = get_bloginfo('url'); | |
} | |
$relative_url = str_replace( | |
$search, | |
'', | |
$src | |
); | |
return $relative_url; | |
} | |
add_action('script_loader_src', 'make_urls_relative'); | |
add_action('style_loader_src', 'make_urls_relative'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment