Redirect a Category Archive to a Page
Sends visitors from a category archive to a hand-built landing page, for example /category/news/ to your Newsroom page, while posts keep their category.
Opens WPIDE on
Code
// Category slug => page path, for example 'news' => '/newsroom/'.
$wpide_category_redirects = array();
add_action( 'template_redirect', function () use ( $wpide_category_redirects ) {
if ( ! is_category() || is_feed() ) {
return;
}
$term = get_queried_object();
if ( $term instanceof WP_Term && isset( $wpide_category_redirects[ $term->slug ] ) ) {
wp_safe_redirect( home_url( $wpide_category_redirects[ $term->slug ] ), 301 );
exit;
}
} );
Notes
The list is empty by default. Map category slugs to paths of pages that exist on your site.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.