Root relative URLs
This commit is contained in:
@@ -124,6 +124,9 @@ add_filter('body_class', 'roots_body_class');
|
|||||||
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
|
* @author Scott Walkinshaw <scott.walkinshaw@gmail.com>
|
||||||
*/
|
*/
|
||||||
function roots_root_relative_url($input) {
|
function roots_root_relative_url($input) {
|
||||||
|
if(!is_admin()) {
|
||||||
|
$input = str_replace(site_url(), "", $input);
|
||||||
|
}
|
||||||
$output = preg_replace_callback(
|
$output = preg_replace_callback(
|
||||||
'!(https?://[^/|"]+)([^"]+)?!',
|
'!(https?://[^/|"]+)([^"]+)?!',
|
||||||
create_function(
|
create_function(
|
||||||
@@ -141,23 +144,6 @@ function roots_root_relative_url($input) {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Terrible workaround to remove the duplicate subfolder in the src of <script> and <link> tags
|
|
||||||
* Example: /subfolder/subfolder/css/style.css
|
|
||||||
*/
|
|
||||||
function roots_fix_duplicate_subfolder_urls($input) {
|
|
||||||
$output = roots_root_relative_url($input);
|
|
||||||
preg_match_all('!([^/]+)/([^/]+)!', $output, $matches);
|
|
||||||
|
|
||||||
if (isset($matches[1][0]) && isset($matches[2][0])) {
|
|
||||||
if ($matches[1][0] === $matches[2][0]) {
|
|
||||||
$output = substr($output, strlen($matches[1][0]) + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
function roots_enable_root_relative_urls() {
|
function roots_enable_root_relative_urls() {
|
||||||
return !(is_admin() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
|
return !(is_admin() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls');
|
||||||
}
|
}
|
||||||
@@ -181,13 +167,12 @@ if (roots_enable_root_relative_urls()) {
|
|||||||
'day_link',
|
'day_link',
|
||||||
'year_link',
|
'year_link',
|
||||||
'tag_link',
|
'tag_link',
|
||||||
'the_author_posts_link'
|
'the_author_posts_link',
|
||||||
|
'script_loader_src',
|
||||||
|
'style_loader_src'
|
||||||
);
|
);
|
||||||
|
|
||||||
add_filters($root_rel_filters, 'roots_root_relative_url');
|
add_filters($root_rel_filters, 'roots_root_relative_url');
|
||||||
|
|
||||||
add_filter('script_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
|
||||||
add_filter('style_loader_src', 'roots_fix_duplicate_subfolder_urls');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user