Try these steps:
Step #1: Replace this:
add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
add_rewrite_rule(
'testimonials/([^/]+)(?:/([0-9]+))?/?$',
'index.php?category_name=testimonials&name=$matches[1]&page=$matches[2]',
'top' // The rule position; either 'top' or 'bottom' (default).
);
}
..with this one:
add_filter( 'category_link', 'custom_category_permalink', 10, 2 );
function custom_category_permalink( $link, $cat_id ) {
$slug = get_term_field( 'slug', $cat_id, 'category' );
if ( ! is_wp_error( $slug ) && 'testimonials' === $slug ) {
$link = home_url( user_trailingslashit( '/testimonials/', 'category' ) );
}
return $link;
}
add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
add_rewrite_rule(
'testimonials(?:/page/?([0-9]{1,})|)/?$',
'index.php?category_name=testimonials&paged=$matches[1]',
'top' // The rule position; either 'top' or 'bottom' (default).
);
add_rewrite_rule(
'testimonials/([^/]+)(?:/([0-9]+))?/?$',
'index.php?category_name=testimonials&name=$matches[1]&page=$matches[2]',
'top' // The rule position; either 'top' or 'bottom' (default).
);
}
Step #2: Go to the Permalink Settings page, and click on the Save Changes button without actually making any changes.