[Resolved] How to Remove Category Prefix From WordPress URL

Tagged: 

  • Author
    Posts
  • #14376

    obito
    Participant

    Hello

    Right now My Current Category Url Like this – mysite.com/category/wordpress/

    But I want to remove the “category” slug from all of the categories. So I want something like this

    mysite.com/wordpress/

    How can I do this?

    Thanks

    #14377

    Andrew Misplon
    Keymaster

    Hi obito

    Thanks for reaching out.

    Try heading over to Settings > Permalinks, the category base should be there as one of the available settings.

    #14390

    obito
    Participant

    Instead, I tried this code,

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

    It works for me, found this guide on this site

    #14378

    obito
    Participant

    I found out the solution myself.

    To remove / item / or / category /, you can go to permalink and insert a dot (.) in the category base field you would like to remove.

    See possibly this guide, it explains it a little better: https://www.mediumtalk.net/remove-category-wordpress-url/

    If you don’t want to change any settings you guys can use a plugin instead: https://en-ca.wordpress.org/plugins/remove-category-url/

    #14398

    Andrew Misplon
    Keymaster

    Super, glad to hear you’ve made progress. Thanks for posting the solution. All the best with your site.

    (bbPress flags some replies, if that happens the replies are saved, they just need to be approved.)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Scroll to top