Skip to content

Instantly share code, notes, and snippets.

@igorveremsky
Created October 11, 2017 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorveremsky/fd5137f636aa20687d504663a29860aa to your computer and use it in GitHub Desktop.
Save igorveremsky/fd5137f636aa20687d504663a29860aa to your computer and use it in GitHub Desktop.
Remove '/category/' from category archive url Wordpress
<?php
/*
* Remove '/category/' from category archive url
* */
function remcat_function($link) {
return str_replace("/category/", "/", $link);
}
add_filter('user_trailingslashit', 'remcat_function');
function remcat_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init', 'remcat_flush_rules');
function remcat_rewrite($wp_rewrite) {
$new_rules = array('(.+)/page/(.+)/?' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&paged='.$wp_rewrite->preg_index(2));
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'remcat_rewrite');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment