Remove category & tag base from WordPress url - without a plugin

I would like to remove the category & tag base from WordPress URL. I have come across other posts and solutions which used plugins. I would like to stay away from plugins and have a solution from within functions.php. This would prevent any future plugin updates or WordPress default files from being changed.

Any help would be appreciated. Thanks!

I have tried these solutions so far:

  • This htaccess solution did not work: http://mikepayne.co/2011/remove-category-base-from-url/
  • These methods also failed: http://www.askapache.com/wordpress/remove-category-wordpress-urls.html

Solution 1:

If you want to remove /category/ from the url, follow these two steps:

  1. Go to Settings >> Permalinks and select Custom and enter: /%category%/%postname%/
  2. Next set your Category Base to .

Save it and you’ll see your URL changed to this format: http://yourblog.com/quotes/

(Source: http://premium.wpmudev.org/blog/daily-tip-quick-trick-to-remove-category-from-wordpress-url/)

Solution 2:

If you use Yoast SEO plugin just go to:

Search Appearance > Taxonomies > Category URLs.

And select remove from Strip the category base (usually /category/) from the category URL.

Regarding the tag removal I did not found any solution yet.

Solution 3:

  1. Set Custom Structure: /%postname%/
  2. Set Category base: . (dot not /)

  3. Save. 100% work correctly.

Solution 4:

Whilst you dismiss it as a solution, the plugin is by far the easiest and most consistent method and they don't change any WordPress default files.

http://wordpress.org/plugins/wp-no-category-base/

It hasn't needed to be updated for a year, so it is not exactly creating any problems with updates.

There is no simple hand rolled solution that will do all of this that does not just replicate what the plugin does from within your own functions.php

  • Better and logical permalinks like myblog.com/my-category/ and myblog.com/my-category/my-post/.
  • Simple plugin - barely adds any overhead.
  • Works out of the box - no setup needed. No need to modify WordPress files.
  • Doesn't require other plugins to work.
  • Compatible with sitemap plugins.
  • Works with multiple sub-categories.
  • Works with WordPress Multisite.
  • Redirects old category permalinks to the new ones (301 redirect, good for SEO).

Plus you get the benefit that if WordPress does change, then the plugin will be updated to work whilst you would then have to figure out how to fix your own code on your own.