user3390335
user3390335

Reputation:

Wordpress category permalink

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

Upvotes: 6

Views: 12221

Answers (2)

danjah
danjah

Reputation: 1246

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

Upvotes: 1

Mustafa Ehsan Alokozay
Mustafa Ehsan Alokozay

Reputation: 5823

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.

Upvotes: 3

Related Questions