This functionality will be very useful for those users who have long parent-sub category list on his/her site. WordPress have default Categories widget. I am adding the toggle effect there and hiding the all sub categories. Clicking on the “+” icon respective sub categories will expend. Just following the bottom steps and achieve this functionality.
Assuming that you already added the “Categories” widget at your sidebar.
We need to enqueue this js file for front end only. Open the functions.php file and add the following the PHP script there:
This is the last step. Doing some fancy design for professional look. You will change this CSS codes as per your site design. Here is my CSS (style.css file):
If you need any help then you can feel free ask me.