Default Title

Date:

Share post:

Unveiling Empty Categories: A Complete Guide for WordPress Sidebar

By default, WordPress sidebars do not display empty categories. However, there may be situations where you want to showcase empty categories, especially when setting up a new website. In this article, we will provide a step-by-step guide on how to easily show empty categories in your WordPress sidebar. Whether you prefer using code snippets or plugins, we have you covered.

Method 1: Using the WPCode Extension

Instead of adding code snippets to your theme’s functions.php file, it is recommended to use the WPCode extension to avoid any potential risks that could break your website. WPCode is a popular code snippet plugin that allows you to add custom code to your WordPress site safely and easily.

Follow these instructions to get started:

  1. Install and activate the WPCode plugin. You can refer to our detailed guide on how to install a WordPress plugin for more information.

  2. Once activated, go to the “Code Snippets” section and click on “+Add Snippet”. This will take you to the snippet library, which contains a variety of pre-tested shortcodes.

  3. Click on “Add Your Custom Code (New Snippet)” and give a title to the snippet, such as “Empty Categories”.

  4. Change the Code Type to “PHP Snippet” and paste the following code into the Code Preview box:


function custom_category_list($args = '') {
    $custom_args = array(
        'hide_empty' => 0,
        'title_li'   => ''
    );
    $args = wp_parse_args($args, $custom_args);
    return wp_list_categories($args);
}
add_shortcode('custom_categories', 'custom_category_list');
  1. Toggle the switch from “Inactive” to “Active” in the top right corner and click “Save Snippet”.

  2. Scroll down to the “Insertion box”, select the “Shortcode” option next to “Insert Method”, and copy the generated shortcode.

  3. Go to “Appearance ≫ Widgets” in your WordPress admin area. Find the “Main Sidebar” section, click the “+” icon, and choose “Shortcode”.

  4. Paste the shortcode generated by WPCode into the box and click the “Update” button.

Now, you can preview your website to see the list of categories, including empty categories, in action. This shortcode can also be used in WordPress posts and pages, making it convenient for visitors to browse related topics by category.

Method 2: Modifying the Default Category Widget

This method is useful if you are using classic widgets on your WordPress website and have deactivated block widgets. Instead of creating a shortcode, you can modify the behavior of the default category widget.

Follow these steps to implement this method:

  1. Install and activate the WPCode plugin.

  2. Repeat the same steps as Method 1, including the following code in WPCode:


function display_empty_categories($cat_args) {
    $cat_args['hide_empty'] = 0;
    return $cat_args;
}
add_filter('widget_categories_args', 'display_empty_categories');
  1. Add the widget to your sidebar by going to “Appearance ≫ Widgets”. Copy the shortcode generated by WPCode and paste it into a text widget. Save your changes.

Visit your live website to see the modifications. Your list of categories should now include empty categories.

Conclusion

By following the methods outlined in this complete guide, you can easily show empty categories in your WordPress sidebar. This functionality offers greater flexibility when organizing and displaying your website’s content. For more WordPress tips, tricks, and hacks, or for further insights into WordPress theme development, feel free to explore our wide range of resources. Don’t forget to subscribe to our YouTube Channel for engaging WordPress video tutorials and connect with us on Twitter and Facebook.

Subscribe to our newsletter

Stay ahead of the game! Subscribe to our newsletter for exclusive tips and insights on Data Structures & Algorithms and interview preparation.

Leave a Reply

Related articles

10 Effective Growth Hacking Techniques to Boost Your Online Influence**

The Influence of Online Power: 10 Techniques for Boosting Growth In today's digital world, having a strong online presence...

Boost Your Productivity with Checklists: An Essential Tool for Every Blogger and Marketer

The Power of Using Checklists: Enhancing Your Efficiency as a Blogger or Marketer In the fast-paced world we live...

Convert Webpages to PDFs: A Simple Guide**

Finding an easy and reliable way to convert webpages to PDF files can be a daunting task. Many...

Mastering Freelance Success: Key Tips for Building a Thriving Career

Keys to Creating a Successful Freelance Business: Essential Strategies and Techniques Introduction: Flourishing in the Freelance Economy As the gig...