Remove category & tag base from WordPress url - wi

2019-01-02 23:33发布

I would like to remove the category & tag base from wordpress URL. I have come across other posts and solutions which used plugins. I would like to stay away from plugins and have a solution from within functions.php. This would prevent any future plugin updates or wordpress default files from being changed.

Any help would be appreciated. Thanks!

I have tried these solutions so far:

13条回答
小情绪 Triste *
2楼-- · 2019-01-02 23:51

instead put this in your functions.php works fine, no redirect problems.

function fix_slash( $string, $type )
{
global $wp_rewrite;
if ( $wp_rewrite->use_trailing_slashes == false )
{
    if ( $type != 'single' && $type != 'category' )
        return trailingslashit( $string );

    if ( $type == 'single' && ( strpos( $string, '.html/' ) !== false ) )
        return trailingslashit( $string );

    if ( $type == 'category' && ( strpos( $string, 'category' ) !== false ) )
    {
        $aa_g = str_replace( "/category/", "/", $string );
        return trailingslashit( $aa_g );
    }
    if ( $type == 'category' )
        return trailingslashit( $string );
}
return $string;
}

add_filter( 'user_trailingslashit', 'fix_slash', 55, 2 );
查看更多
等我变得足够好
3楼-- · 2019-01-02 23:51

The non-category plugin did not work for me.

For Multisite WordPress the following works:

  1. Go to network admin sites;
  2. Open site under \;
  3. Go to settings;
  4. Under permalinks structure type /%category%/%postname%/. This will display your url as www.domainname.com/categoryname/postname;
  5. Now go to your site dashboard (not network dashboard);
  6. Open settings;
  7. Open permalink. Do not save (the permalink will show uneditable field as yourdoamainname/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.
查看更多
Emotional °昔
4楼-- · 2019-01-02 23:56

https://wordpress.org/plugins/remove-category-url/ Use this plugin it does the job perfectly of hiding the category-base It does not require any setting just install and activate.

查看更多
爷的心禁止访问
5楼-- · 2019-01-03 00:02

Select Custom Structure in permalinks and add /%category%/%postname%/ after your domain. Adding "/" to the category base doesn't work, you have to add a period/dot. I wrote a tutorial for this here: remove category from URL tutorial

查看更多
Juvenile、少年°
6楼-- · 2019-01-03 00:03

I liked this solution:

If you want to remove /category/ from the url, follow these two steps:

  1. Go to Settings >> Permalinks and select Custom and enter: /%category%/%postname%/
  2. Next set your Category Base to .

Save it and you’ll see your URL changed to this format: http:/yourblog.com/quotes/

(Source: http://premium.wpmudev.org/blog/daily-tip-quick-trick-to-remove-category-from-wordpress-url/)

查看更多
干净又极端
7楼-- · 2019-01-03 00:03

If you're still searching for the combination (tags, categories and pages on the url-base), you can do it like I did.

Tested using Wordpress 3.9.1

If you have pages, categories or tags having the same name, the system will take:

  1. tag
  2. page
  3. category
查看更多
登录 后发表回答