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
If you use
Yoast SEO
plugin just go to:And select
remove
fromStrip the category base (usually /category/) from the category URL
.Regarding the tag removal I did not found any solution yet.
Adding "." or "/" won't work if you want a consolidated blog view. Also, I have know idea what that solutions would do for the RSS or XML feeds. I feel better sticking with the WP convention. However, I did come up with a more elegant approach.
First, I name the base category url "blog"
Then I created a category called "all". Finally, I but all my subcategories under "all". So I get a url structure like this.
I put a custom label on the menu item called "Blog", but it goes to blog/all. It would be a good idea to 301 redirect /blog to /blog/all in the .htaccess file to avoid the 404 on /blog.
updated answer:
other solution:
In wp-includes/rewrite.php file, you'll see the code:
$this->category_structure = $this->front . 'category/';
just copy whole function, put in your functions.php and hook it. just change the above line with:$this->category_structure = $this->front . '/';
Set Category base: . (dot not /)
Save. 100% work correctly.
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
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.