I presently have 200 class pages and a url construction like this: web site.com/category-name however now I want so as to add mum or dad classes with a view to set up all of the classes.
The issue I’ve is that each one the URL:s within the sitemap will change, which may have a lethal affect on my visitors from a search engine optimisation perspective.
I take advantage of the next code to take away the mum or dad class from the URL so the URL is not as follows: web site.com/parent-name/category-name/ however this doesn’t change the url within the sitemap after all. How would you remedy this predicament?
// Add our customized class rewrite guidelines
add_filter('category_rewrite_rules', 'no_category_parents_rewrite_rules');
operate no_category_parents_rewrite_rules($category_rewrite) {
//print_r($category_rewrite); // For Debugging
$category_rewrite=array();
$classes=get_categories(array('hide_empty'=>false));
foreach($classes as $class) {
$category_nicename = $category->slug;
$category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect help from Outdated Class Base
world $wp_rewrite;
$old_base = $wp_rewrite->get_category_permastruct();
$old_base = str_replace( '%class%', '(.+)', $old_base );
$old_base = trim($old_base, "https://wordpress.stackexchange.com/");
$category_rewrite[$old_base.'$'] = 'index.php?category_redirect=$matches[1]';
//print_r($category_rewrite); // For Debugging
return $category_rewrite;
}
// Add 'category_redirect' question variable
add_filter('query_vars', 'no_category_parents_query_vars');
operate no_category_parents_query_vars($public_query_vars) {
$public_query_vars[] = 'category_redirect';
return $public_query_vars;
}
// Redirect if 'category_redirect' is ready
add_filter('request', 'no_category_parents_request');
operate no_category_parents_request($query_vars) {
//print_r($query_vars); // For Debugging
if(isset($query_vars['category_redirect'])) {
$catlink = trailingslashit(get_option( 'house' )) . user_trailingslashit( $query_vars['category_redirect'], 'class' );
status_header(301);
header("Location: $catlink");
exit();
}
return $query_vars;
}