to dirprocess: removing 'category' from url rev 21 apr 2020
Category: web:cms:cp/wp
By default CP/WP put the string 'category' before the name of the
category in the archive listing. Like:
https://yourdomain.tld/category/news/
In Settings -> Permalinks - Category Base
you can change the word 'category' to something else,
like 'topics'.
Sometimes it would be nicer to have it like
https://yourdomain.tld/news/
.......................................................
how-tos:
In Settings -> Permalinks:
- Change "Category Base" to period/dot.
In .htaccess:
RewriteRule ^category/(.+)$ https://www.site.com/$1 [R=301,L]
In functions.php:
add_filter( 'user_trailingslashit', 'remove_category', 100, 2);
function remove_category( $string, $type ) {
if ( $type != 'single' && $type == 'category' && ( strpos( $string, 'category' ) !== false ) ) {
$url_without_category = str_replace( "/category/", "/", $string );
return trailingslashit( $url_without_category );
}
return $string;
}
.......................................................
Resources:
* How To Remove Category From Your URLs In WordPress
https://jonnyjordan.com/blog/how-to-remove-category-from-your-urls-in-wordpress/
* How To Remove the Category From the WordPress URL
https://muffingroup.com/blog/remove-category-from-wordpress-url/
_______________________________________________________
begin 20 feb 2021
-- 0 --