Skip to content

WordPress: Remove Category From The URL

wordpress-remove-category-from-url

Here there is a method that will edit out the category/ url structure that wordpress ads by default.
Instead of “www.yourweb.com/category/worpress-notes/”
It will read “www.yourweb.com/wordpress-notes/”

First of all:
Go to DASHBOARD
>Settings
>Permalinks

Under Custom Structure type:

/%category%/%postname%/

And Save.

Then, go to:
DASHBOARD
>Appearance
>Editor

Add the following code at the end of your functions.php file.

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;
}

Thanks to WebDevTuts.com

Read more from WordPress

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

*