Remove Base Category from WordPress Category URL

I caught a solution for this on the Internet, tried a plugin or two to remove / category / from wordpress url.

Although some of these plugins are good, the category link is still displayed / category /.

I also tried to insert ./ into the basic category options in the permalink settings.

Does anyone know how I can do it like finding and replacing php or something like that?

+4
source share
3 answers

http://wordpress.org/extend/plugins/wp-no-category-base/ , and it does not change permalinks, so deleting it restores the structure without any problems. And you do not need to change the main files.

+2
source

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; } 
+1
source

Using WordPress 3.9.1 (latest version on this post) I just added one line to my functions.php theme ...

 $wp_rewrite->add_permastruct('category_base', '%category%'); 

Then I opened Settings> Permalink and clicked Save. It looks like it clears the permalink cache and makes it work.

+1
source

Source: https://habr.com/ru/post/1347999/


All Articles