• Hi guys.

    Is there any way to get the links like this ?

    site.com/knowledgebase/category/term/

    right now it’s

    site.com/knowledgebase/knowledgebase_category/category

    site.com/knowledgebase/term

    I tried using custom permalinks plugins but not effect.

    Writing each URL isn’t an option either as I will have too many terms.

    Please help, or at least give a direction.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @coadr93 If you want to share how you fixed this, please feel free to do so here.

    Thread Starter coadr93

    (@coadr93)

    Ok, I shall prepare a post this evening.

    Thread Starter coadr93

    (@coadr93)

    A little bit late but haven’t forgot.

    1st of all, please make sure you have a complete backup of your public_html folder and database.

    Playing with URL rewrites might break something. However, this worked fine for me.

    Install WP Knowledgebase, and make sure you define your Knowledgebase Slug in the plugin Settings section.

    Then, install Custom Post Type Permalinks plugin by Toro_Unit.

    https://www.ads-software.com/plugins/custom-post-type-permalinks/

    Make sure you activate it ??

    After this, you have to insert some code to your site.

    To do this, you can edit the theme-functions.php file via Appearance -> Theme editor. However, I do recommend adding a child theme first, as any updates to the theme will erase the code and break your URLs.

    You can also use the Pluginception plugin to create a new blank plugin and add the code there.

    DON’T FORGET to replace YOURSLUG with… well… your slug xD

    
    // Rewrite URL Rules
    
    add_action( 'generate_rewrite_rules', 'register_kbe_knowledgebase_rewrite_rules' );
    function register_kbe_knowledgebase_rewrite_rules( $wp_rewrite ) {
    	$new_rules = array( 
    		'YOURSLUG/([^/]+)/?$' => 'index.php?kbe_taxonomy=' . $wp_rewrite->preg_index( 1 ),
    		'YOURSLUG/([^/]+)/([^/]+)/?$' => 'index.php?post_type=kbe_knowledgebase&kbe_taxonomy=' . $wp_rewrite->preg_index( 1 ) . '&kbe_knowledgebase=' . $wp_rewrite->preg_index( 2 ),
    		'YOURSLUG/([^/]+)/([^/]+)/page/(\d{1,})/?$' => 'index.php?post_type=kbe_knowledgebase&kbe_taxonomy=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 3 ),
    		'YOURSLUG/([^/]+)/([^/]+)/([^/]+)/?$' => 'index.php?post_type=kbe_knowledgebase&kbe_taxonomy=' . $wp_rewrite->preg_index( 2 ) . '&kbe_knowledgebase=' . $wp_rewrite->preg_index( 3 ),
    	);
    
    	$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }
    
    // A hacky way of adding support for flexible custom permalinks
    // There is one case in which the rewrite rules from register_kb_rewrite_rules() fail:
    // When you visit the archive page for a child section(for example: https://example.com/kbe_knowledgebase/category/child-category)
    // The deal is that in this situation, the URL is parsed as a Knowledgebase post with slug "child-category" from the "category" section
    

    After this, configure the Custom Permalinks Settings (General Settings -> Permalinks) like this:

    Where it says kbe_knowledgebase https://yoursite.com/YOURSLUG add this:

    
    /%kbe_taxonomy%/%postname%/
    

    Then, check the box under, where it says “Use custom permalink of custom taxonomy archive. If you check this, the custom taxonomy’s permalinks will be https://yoursite.com/post_type/taxonomy/term”

    Click save permalinks and it should do the trick.

    • This reply was modified 7 years, 1 month ago by coadr93.
    • This reply was modified 7 years, 1 month ago by coadr93.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hierarchical URLs’ is closed to new replies.