diff --git a/functions.php b/functions.php index 2ca45c0..0f5b9f7 100644 --- a/functions.php +++ b/functions.php @@ -12,6 +12,7 @@ require_once locate_template('/lib/cleanup.php'); // Cleanup require_once locate_template('/lib/nav.php'); // Custom nav modifications require_once locate_template('/lib/comments.php'); // Custom comments modifications require_once locate_template('/lib/rewrites.php'); // URL rewriting for assets +require_once locate_template('/lib/relative-urls.php'); // Root relative URLs require_once locate_template('/lib/widgets.php'); // Sidebars and widgets require_once locate_template('/lib/scripts.php'); // Scripts and stylesheets require_once locate_template('/lib/custom.php'); // Custom functions diff --git a/lib/cleanup.php b/lib/cleanup.php index 7f134ed..0b16711 100644 --- a/lib/cleanup.php +++ b/lib/cleanup.php @@ -126,54 +126,6 @@ function roots_body_class($classes) { } add_filter('body_class', 'roots_body_class'); -/** - * Root relative URLs - * - * WordPress likes to use absolute URLs on everything - let's clean that up. - * Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/ - * - * You can enable/disable this feature in config.php: - * current_theme_supports('root-relative-urls'); - * - * @author Scott Walkinshaw - */ -function roots_root_relative_url($input) { - preg_match('|https?://([^/]+)(/.*)|i', $input, $matches); - - if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) { - return wp_make_link_relative($input); - } else { - return $input; - } -} - -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'); -} - -if (roots_enable_root_relative_urls()) { - $root_rel_filters = array( - 'bloginfo_url', - 'the_permalink', - 'wp_list_pages', - 'wp_list_categories', - 'roots_wp_nav_menu_item', - 'the_content_more_link', - 'the_tags', - 'get_pagenum_link', - 'get_comment_link', - 'month_link', - 'day_link', - 'year_link', - 'tag_link', - 'the_author_posts_link', - 'script_loader_src', - 'style_loader_src' - ); - - add_filters($root_rel_filters, 'roots_root_relative_url'); -} - /** * Wrap embedded media as suggested by Readability * diff --git a/lib/relative-urls.php b/lib/relative-urls.php new file mode 100644 index 0000000..56ee615 --- /dev/null +++ b/lib/relative-urls.php @@ -0,0 +1,48 @@ + + */ +function roots_root_relative_url($input) { + preg_match('|https?://([^/]+)(/.*)|i', $input, $matches); + + if (isset($matches[1]) && isset($matches[2]) && $matches[1] === $_SERVER['SERVER_NAME']) { + return wp_make_link_relative($input); + } else { + return $input; + } +} + +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'); +} + +if (roots_enable_root_relative_urls()) { + $root_rel_filters = array( + 'bloginfo_url', + 'the_permalink', + 'wp_list_pages', + 'wp_list_categories', + 'roots_wp_nav_menu_item', + 'the_content_more_link', + 'the_tags', + 'get_pagenum_link', + 'get_comment_link', + 'month_link', + 'day_link', + 'year_link', + 'tag_link', + 'the_author_posts_link', + 'script_loader_src', + 'style_loader_src' + ); + + add_filters($root_rel_filters, 'roots_root_relative_url'); +}