Skip to content

Instantly share code, notes, and snippets.

@0x46616c6b
Last active January 3, 2016 12:29
Show Gist options
  • Save 0x46616c6b/8463156 to your computer and use it in GitHub Desktop.
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!
<?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