Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Maeve Lander

    (@enigmaweb)

    I’m afraid that’s hardcoded in the plugin sorry Yaniv. You could change it yourself if you don’t mind modifying the plugin code? Just run a search and replace in the relevant files. However be aware this would be overwritten when you update the plugin so unless it’s mission critical, I would advise sticking with knowledgebase_category.

    We’ll look into improving this or making it customisable in the future.

    +1 to that request. It’s so easy to make pretty-looking slugs everywhere else, this bit took me completely by surprise (and I would rather not mess with the plugin itself).

    +1 to that request. Please.

    +1 for this request as well. I like beautiful, customizable slugs and this one throws me off. :/

    I’d also prefer to not have to mess with core plugin files to get this functionality. Maybe we can get some sort of filter or something to change it in the future?

    Actually, after thinking about this a bit more, we should be able to change the category structure without modifying core code using something like the following (put in your functions.php):

    function kb_modify_category_taxonomy() {
        // get the arguments of the already-registered taxonomy
        $kb_category_args = get_taxonomy( 'kbe_taxonomy' ); // returns an object
    
        // make changes to the args
        $kb_category_args->show_admin_column = true;
        $kb_category_args->rewrite['slug'] = 'collections'; //change this to your category structure
        $kb_category_args->rewrite['with_front'] = true;
    
        // re-register the taxonomy
        register_taxonomy( 'kbe_taxonomy', 'kbe_knowledgebase', (array) $kb_category_args );
    }
    // hook it up to 11 so that it overrides the original register_taxonomy function
    add_action( 'init', 'kb_modify_category_taxonomy', 11 );

    The above example will change the category structure from:

    mysite.com/knowledgebase_category/general
    to
    mysite.com/collections/general

    Likewise, if you wanted to change the tag structure:

    function kb_modify_tag_taxonomy() {
        // get the arguments of the already-registered taxonomy
        $kb_tag_args = get_taxonomy( 'kbe_tags' ); // returns an object
    
        // make changes to the args
        $kb_tag_args->show_admin_column = true;
        $kb_tag_args->rewrite['slug'] = 'kb-topics'; // change to your tag structure of choice
        $kb_tag_args->rewrite['with_front'] = true;
    
        // re-register the taxonomy
        register_taxonomy( 'kbe_tags', 'kbe_knowledgebase', (array) $kb_tag_args );
    }
    // hook it up to 11 so that it overrides the original register_taxonomy function
    add_action( 'init', 'kb_modify_tag_taxonomy', 11 );

    The above example will change the tag structure from:

    mysite.com/knowledgebase_tags/general
    to
    mysite.com/kb-topics/general

    *Important: Make sure to re-save your permalink structure after adding the snippet(s).

    Apparently their could potentially be an issue with the above solution and capabilities… blargh.

    Alternatively we should be able to use the following snippet for categories as well. It uses the register_taxonomy_args filter that was introduced in register_taxonomy() in 4.4 (based on this post):

    add_filter( 'register_taxonomy_args', function ( $args, $taxonomy, $object_type )
    {
        // Only target the build in taxonomy 'kbe_taxonomy' aka 'knowledgebase_category'
        if ( 'kbe_taxonomy' !== $taxonomy )
            return $args;
    
        // Change the slug to our value
        $args["rewrite"]["slug"] = 'collections';
    
        return $args;
    }, 10, 3);

    If you use this method you still want to re-save your permalinks.

    Plugin Contributor Maeve Lander

    (@enigmaweb)

    Thanks for posting your solution @amber.

    We will definitely look into adding the ability to customise slugs in the future. Right now we’re working on a major release which cleans up a lot of code, adds some new features (mainly behind the scenes for developers) and which will make future development much more streamlined. Once that’s finished we’ll start going through requests and tackle new features like this.

    Thanks again for your patience all.

    Any update on the slug customisations?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to change category slug’ is closed to new replies.