Title: Sub category shortcode
Last modified: December 16, 2025

---

# Sub category shortcode

 *  Resolved [fabricationcrafts](https://wordpress.org/support/users/fabricationcrafts/)
 * (@fabricationcrafts)
 * [5 months, 3 weeks ago](https://wordpress.org/support/topic/sub-category-shortcode/)
 * Hi is a it possible to add sub categories to the single categories page using
   a shortcode, to filter further

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [fabricationcrafts](https://wordpress.org/support/users/fabricationcrafts/)
 * (@fabricationcrafts)
 * [5 months, 3 weeks ago](https://wordpress.org/support/topic/sub-category-shortcode/#post-18758495)
 * I’ve added a shortcode but it’s pulling the listings up in those categories not
   the subcategories, even if i list them or the id
 *  Plugin Support [Al-Amin Khan](https://wordpress.org/support/users/alamin56649/)
 * (@alamin56649)
 * [5 months, 2 weeks ago](https://wordpress.org/support/topic/sub-category-shortcode/#post-18759581)
 * Hi [@fabricationcrafts](https://wordpress.org/support/users/fabricationcrafts/),
 * By default, Directorist does not support displaying subcategories on a single
   category page via shortcode in the way you described. The standard shortcodes
   will pull listings from the selected categories, not dynamically list child subcategories.
 * That said, you can achieve this behavior with a bit of custom code. The snippet
   below creates a custom shortcode that will first display the **child categories**
   of the current category and then show the **listings from the parent category**.
 * You can add the code below to your theme’s `functions.php` file or use a code
   snippet plugin to apply it safely:
 *     ```wp-block-code
       /** * Shortcode: [directorist_advanced_category ...any directorist_category attrs...] * * Works on a Directorist category archive where the current term slug * is available via get_query_var('atbdp_category'). * Shows child categories first, then parent category listings. */add_shortcode('directorist_advanced_category', function ($atts = [], $content = null) {    $orig_atts = is_array($atts) ? $atts : [];    // Helper to build safe shortcode attribute string    $build_attr_str = function(array $a) {        $pairs = [];        foreach ($a as $k => $v) {            if ($v === '' || $v === null) continue;            $k = sanitize_key($k);            if (is_array($v)) { $v = implode(',', array_map('sanitize_text_field', $v)); }            $pairs[] = sprintf('%s="%s"', $k, esc_attr($v));        }        return implode(' ', $pairs);    };    // Get current category slug from query var    $current_slug = get_query_var('atbdp_category');    if (!$current_slug) {        return do_shortcode('[directorist_category ' . $build_attr_str($orig_atts) . ']');    }    $parent = get_term_by('slug', $current_slug, ATBDP_CATEGORY);    if (!$parent || is_wp_error($parent)) {        return do_shortcode('[directorist_category ' . $build_attr_str($orig_atts) . ']');    }    $output = '';    // Gather child categories first    $child_terms = get_terms([        'taxonomy'   => ATBDP_CATEGORY,        'parent'     => (int) $parent->term_id,        'hide_empty' => false,    ]);    if (!is_wp_error($child_terms) && !empty($child_terms)) {        $child_slugs = [];        foreach ($child_terms as $child) {            $child_slugs[] = $child->slug;        }        $child_slugs = array_values(array_unique($child_slugs));        if (!empty($child_slugs)) {            $all_cats_attr = 'slug="' . esc_attr(implode(',', $child_slugs)) . '"';            $output .= do_shortcode('[directorist_all_categories view="grid" ' . $all_cats_attr . ']');        }    }    // Then display all parent category listings    $output .= do_shortcode('[directorist_category slug="' . esc_attr($parent->slug) . '" ' . $build_attr_str($orig_atts) . ']');    return $output;});add_filter('atbdp_all_categories_argument', function($args){    if(get_directorist_option('single_category_page')) unset($args['parent']);    return $args;});
       ```
   
 * After adding this, you can use the shortcode below on your category page:
 *     ```wp-block-code
       [directorist_advanced_category]
       ```
   
 * Please give this a try and let me know how it works on your end.
 * Best regards,
   Al-Amin Khan
 *  Thread Starter [fabricationcrafts](https://wordpress.org/support/users/fabricationcrafts/)
 * (@fabricationcrafts)
 * [5 months, 2 weeks ago](https://wordpress.org/support/topic/sub-category-shortcode/#post-18759815)
 * great thanks, I’ll have a play and let you know how I get on 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsub-category-shortcode%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/directorist/assets/icon-256x256.gif?rev=3185058)
 * [Directorist: AI-Powered Business Directory, Listings & Classified Ads](https://wordpress.org/plugins/directorist/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/directorist/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/directorist/)
 * [Active Topics](https://wordpress.org/support/plugin/directorist/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/directorist/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/directorist/reviews/)

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)

 * 3 replies
 * 2 participants
 * Last reply from: [fabricationcrafts](https://wordpress.org/support/users/fabricationcrafts/)
 * Last activity: [5 months, 2 weeks ago](https://wordpress.org/support/topic/sub-category-shortcode/#post-18759815)
 * Status: resolved