Try these steps:
Step #1: Replace this:
add_action('generate_rewrite_rules', 'custom_rewrite_rules');
function custom_rewrite_rules( $wp_rewrite ) {
$regex = '/[\s\S]/';
$new_rules = array(
trailingslashit('testimonials/'.$regex) => '/?p='. get_page_by_path('$matches[1]', OBJECT, 'post')->id
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
..with this one:
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).
);
}
Step #2: Go to the Permalink Settings page, and click on the Save Changes button without actually making any changes.