5

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/.

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?

daryl
  • 14,307
  • 21
  • 67
  • 92
  • Looks promising -- http://pitumbo.com/remove-category-and-or-tag-url-wordpress-3 – stealthyninja Apr 13 '11 at 22:47
  • Nah not what I'm looking for. I resorted to editing the rewrite.php core file. Problem solved. – daryl Apr 13 '11 at 22:50
  • 1
    "Problem solved." Actually, problem made more complex by altering WP core. – markratledge Apr 15 '11 at 16:44
  • I am using a [WordPress plugin to remove category base](http://www.wordpressians.com/remove-category-slug-base-wordpress-urls/) from our WordPress blog. Hope this may help you the most. Best Regards! – WordPressians Aug 11 '12 at 14:14

4 Answers4

3

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;
}
Littm
  • 4,923
  • 4
  • 30
  • 38
Geek
  • 39
  • 1
3

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.

Simon East
  • 55,742
  • 17
  • 139
  • 133
  • i tried this option, but when i try to go to a subcategory page, it is confusing wordpress and it's taking me to a post with a similar slug to my category. – Robbiegod Nov 04 '22 at 16:41
2

http://wordpress.org/extend/plugins/wp-no-category-base/ and it doesn't alter permalinks, so removing it reverts the structure with no problem. And you don't have to alter core files.

markratledge
  • 17,322
  • 12
  • 60
  • 106
  • Yes I already tried that plugin. It didn't do what I wanted it to as it still displayed the links in the HTML with /category at the base, although it re-directs to the page without the /category. – daryl Apr 15 '11 at 17:39
  • As I found this post and the plugin mentioned is now outdated, here is a new plugin currently being used and maintained, that should do the job: https://wordpress.org/plugins/no-category-base-wpml/ – Ingo Steinke Dec 30 '19 at 13:16
0

https://wordpress.org/plugins/no-category-base-wpml/ is a plugin that solves the problem and works with current versions of WordPress.

Ingo Steinke
  • 766
  • 3
  • 11
  • 30