WordPress remove category from url
To remove category slug from existing posts, do this :
- Navigate to Settings > Permalinks and change Custom Structure from
/%category%/%postname%/
to:/%postname%/
- Keep Category and Tag bases empty (which is the default also)
- Save
All posts can now be directly accessed via Your
and all categories can be accessed via Domain.com
/%postname%/Your
. WordPress will automatically add all the 301 redirects for the old URLs. So, if someone accesses YourDomain.com
/category/abc/Domain.com/%category%/%postname%/
they will automatically get redirected to Your
Domain.com
/%postname%/
Remove Category in WordPress Permalinks
- Go to your admin dashboard.
- Go to Settings >> Permalinks >> Optional >> Category base.
- Enter your customized category base (e.g. ‘Articles’) or Choose Post-name
- Save the changes.
Removing Category by Adding a Code in functions.php File
- Go to your WordPress dashboard.
- Select Appearance >> Theme Editor.
- Find ‘functions.php’.
- Type the following code before the last PHP tag:
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; } add_filter( 'user_trailingslashit', 'remove_category', 100, 2);
Using Yoast’s SEO Plugin to Remove Category from WordPress URL
- Go to your WordPress dashboard.
- Select Yoast SEO >> Search Appearance>> Taxonomies
- Go to Category URLs and select ‘Remove the categories prefix’.
- Save the changes.
Modifying .htaccess to Remove Category From WordPress URL
- Login via FTP or cPanel
- Go to your .htaccess file.
- Add the following code after the closing tag in the file:
RewriteRule ^category/(.+)$ https://www.YourDomain.com/$1 [R=301,L]
- Write your domain name in place of www.YourDomain.com or YourDomain.com in the code above.
- Upload it on your server’s public_html directory.
Without plugin wordpress remove category from url
For Multisite WordPress the following works:
- Go to network admin sites;
- Open site under
/
; - Go to settings;
- Under permalinks structure type
/%category%/%postname%/
. This will display your url aswww.DomainName.com/categoryname/postname
; - Now go to your site dashboard (not network dashboard);
- Open settings;
- Open permalink. Do not save (the permalink will show uneditable field as
www.DomainName.com/blog/
. Ignore it. If you save now the work you did in step 4 will be overwritten. This step of opening permalink page but not saving in needed to update the database.