From 60de8ec26f5821aeb31c9322fcd82f40687d8d84 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 13 Feb 2010 06:17:59 +0000 Subject: [PATCH] Canonicalisation of the Taxonomy urls. Redirect /category/child/ to /category/parent/child/. Fix striping of slashes to use $redirect instead of $original. See #8948 git-svn-id: https://develop.svn.wordpress.org/trunk@13091 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/canonical.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index c57addf914..7bbb0813c7 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -139,6 +139,21 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { $redirect['query'] = remove_query_arg('author', $redirect['query']); } + // redirect sub-terms of taxonomies to their correct urls + if ( is_category() || is_tax() ) { + if ( is_category() ) { + $taxonomy = 'category'; + $slug = get_query_var('category_name'); + } else { + $taxonomy = get_query_var('taxonomy'); + $slug = get_query_var('term'); + } + if ( $tax_url = get_term_link($slug, $taxonomy) ) { + $tax_url = parse_url($tax_url); + $redirect['path'] = $tax_url['path']; + } + } + // paging and feeds if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { if ( !$redirect_url ) @@ -257,7 +272,7 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { // Strip multiple slashes out of the URL if ( strpos($original['path'], '//') > -1 ) - $redirect['path'] = preg_replace('|/+|', '/', $original['path']); + $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); // Always trailing slash the Front Page URL if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) )