Remove Category Base from WordPress Category URL

I fished around the internet for a solution to this, tried a plugin or two to remove the /category/ from wordpress url’s.

While some of these plugins are good, the category link still display’s /category/.

Read More

Also I’ve tried putting in ./ in the category base options in permalinks settings.

Does anyone know how I could do like a php search and replace or something like that?

Related posts

Leave a Reply

4 comments

  1. A cleaner solution:

    add_filter('user_trailingslashit', 'remcat_function');
    function remcat_function($link) {
        return str_replace("/category/", "/", $link);
    }
    add_action('init', 'remcat_flush_rules');
    function remcat_flush_rules() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
    add_filter('generate_rewrite_rules', 'remcat_rewrite');
    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;
    }
    
  2. Using WordPress 3.9.1 (latest version as of this post) I simply added a single line to my theme’s functions.php

    $wp_rewrite->add_permastruct('category_base', '%category%');
    

    Then I opened Settings > Permalinks and hit Save. This appears to flush the permalink cache and makes it work.