Resolved

How to Remove Category Prefix From WordPress URL

Ultra Theme started by obito May 8, 2020 4 replies
obito May 8, 2020 · 10:05 am #14376

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

Andrew Misplon Puro May 8, 2020 · 10:18 am #14377

Hi obito

Thanks for reaching out.

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

obito May 8, 2020 · 11:04 am #14390

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

Andrew Misplon Puro May 8, 2020 · 12:50 pm #14398

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

5 posts
Closed This topic is closed to new replies. Still stuck? Start a new topic in Ultra Theme.