Show parent category AND child category in url


Currently I have the following structure:

-Parent Category A
–Children Category A1
–Children Category A2
-Parent Category B
–Children Category B1
–Children Category B2

If a listing belongs to the category ‘Children Category A1’ the url is this:

However, I need the structure to be as follows:

How can I achieve this?


Unfortunately, there’s no such feature, it would require a custom implementation. If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work

Thanks andrii.

But, removing the parent category in the url is a feature of HivePress right? I mean, by default, WordPress writes urls like this: “

Wouldn’t it be enough to disable the HP function that rewrites this?


This is a non-standard WordPress permalink structure (at least for custom post types), but it may be possible with some tweaks, please try these instructions How to add custom taxonomy in custom post type permalink? | Listings have the “hp_listing” post type, listing categories have “hp_listing_category” taxonomy.

Thanks @andrii

I have written a function that, in my case, works well. I leave it here in case it is of help to someone else:

function custom_taxonomy_permalink($permalink, $term, $taxonomy) {
    if ($taxonomy == 'hp_listing_category' && $term->parent > 0) {
        $parent = get_term($term->parent, $taxonomy);
        $permalink = str_replace($term->slug, $parent->slug . '/' . $term->slug, $permalink);
    return $permalink;
add_filter('term_link', 'custom_taxonomy_permalink', 10, 3);

function custom_rewrite_rule() {
    add_rewrite_rule('^listing-category/([^/]*)/([^/]*)/?', 'index.php?taxonomy=hp_listing_category&term=$matches[2]', 'top');
add_action('init', 'custom_rewrite_rule');


1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.