5

I have a wordpress based website and the default category permalink is like "website.com/category/category-slug"

How can I make it look like "website.com/category-slug"? Of course I will always take care that there is no post/page with the same slug

2 Answers2

2

There are two solutions for it:

Solution 1 (simple one):

For removing /category/ from the URLs, do as follow:

Step 1: Go to Settings > Permalinks, select Custom Structure and enter the following into textbox:

enter image description here

Step 2: In Category Base enter / as follow:

enter image description here

Step 3: Save it and your URLs will be http://website.com/category-slug.


Solution 2:

Although not updated for 2 years but a very flexible plugin. Simple install this plugin: WP No Category Base.

Community
  • 1
  • 1
Mustafa Ehsan Alokozay
  • 5,583
  • 2
  • 24
  • 30
  • But this way the single post will look like "website.com/category-slug/post-slug" while I want them to show "website.com/post-slug" just as like the categories –  Oct 06 '15 at 07:06
  • Updated my answer with **solution 2**. See if that can help. – Mustafa Ehsan Alokozay Oct 06 '15 at 07:08
  • That's actually helpful but I'd prefer not to use any plugin and even if I did, I'd like to know how the plugin manages to do that, as it looks like a very small issue. And btw I only have two categories so the whole thing is quite static, I hoped it could have been done with one or two rewrite rules –  Oct 06 '15 at 07:11
  • Although this one is very old, I still have the same question. I would love to know if there are new solutions in all of these years. – JW Geertsma Nov 20 '20 at 13:37
1

This should work, although not tested. Fill in the categoryID below and set your desired URL in wp_redirect().

<?php
$category_id = xx;
$category_link = get_category_link( $category_id )
wp_redirect( $category_link, 'http://www.website.com/category-slug' ); exit;
?>

Remember by the way that wp_redirect() always should be followed by exit; (Source: Codex).

danjah
  • 1,226
  • 1
  • 12
  • 27
  • Are you sure that this works as a rewrite rule? I don't just want to redirect the page to another URL, so that it ends up looking like "website.com/category/slug" but I want it to BE "website.com/slug" when you load the page. And where am I supposed to add this lines? –  Oct 06 '15 at 07:20
  • 1
    Well, actually, Mustafa Ehsans solution 1 seems like the better one. I'd go with that. – danjah Oct 06 '15 at 07:22
  • But can I do that without Step 1? I don't wanna change the single post permalink, I want both single posts and categories look like "website.com/slug" –  Oct 06 '15 at 07:28
  • After doing a little more research it seems like a plugin might be the best way to go. You could also download it, pick out the pieces you want, and put them i functions.php. But that might be a little time consuming. Anyway, this seems like a good plugin - and its supported; https://wordpress.org/plugins/remove-category-url/ – danjah Oct 06 '15 at 07:40