Remove Trailing Slash from Category Base and Tag Base

I did a lot of digging and I came up with this code to solve the problem as well as adding “.html” to pages, categories and tags. The permalink setting takes care of posts.

function hpct_page_rewrite($rules) {
  foreach ($rules as $key => $value) {
    $newrules[str_replace('/?', '.html', $key)] = $value;
  }
  return $newrules;
}
function hpct_page_link($link) {
  return $link . '.html';
}
function hpct_category_rewrite($rules) {
  foreach ($rules as $key => $value) {
    $newrules[str_replace('/?', '.html', $key)] = $value;
  }
  return $newrules;
}
function hpct_category_link($link) {
  return str_replace('category/', 'category-', $link) . '.html';
}
function hpct_tag_rewrite($rules) {
  foreach ( $rules as $key => $value ) {
    $newrules[str_replace('/?', '.html', $key)] = $value;
  }
  return $newrules;
}
function hpct_tag_link($link) {
  return str_replace('tag/', 'tag-', $link) . '.html';
}
add_filter('page_rewrite_rules', 'hpct_page_rewrite', 3);
add_filter('page_link', 'hpct_page_link', 1);
add_filter('category_rewrite_rules', 'hpct_category_rewrite', 3);
add_filter('category_link', 'hpct_category_link', 1);
add_filter('tag_rewrite_rules', 'hpct_tag_rewrite', 3);
add_filter('tag_link', 'hpct_tag_link', 1);

Yes, it’s hard-coded as well and I’ll eventually take care of it. But at least I can do this from within WordPress.