i want to redirect separately all categories to specific pages. Found this code, but this is only for one category to one page, i need to this fo 20 categories to 20 different pages.
function custom_category_template_redirect() {
if ( is_product_category() ) {
$category = get_queried_object();
if ( $category->term_id == 29, ) {
$redirect_page_id = 304;
wp_redirect( get_permalink( $redirect_page_id ) );
exit();
}
}
}
add_action( 'template_redirect', 'custom_category_template_redirect' );
Someone to help me to resolve this case.
It's easy… you need to set an array of product category term IDs (keys) => redirection page IDs (values) pairs, in your function, like:
Code goes in functions.php file of your child theme (or in a plugin). Tested and work.