Collapsible Categories in Admin for WordPress
If you have many, many categories in WordPress, it can be a pain to manage them all. I wrote some code to do this using jQuery, and thought I would share. First you need to override WordPress’ default behavior for categories, which is to show the selected categories at the top, removing them from their position in the tree. You can bypass this by installing the Category Checklist Tree plugin. Without this plugin installed, my code will not help you much.
What my code does is to first collapse the whole categories tree, so that all subcategories are hidden, but it only does this if none of the subcategories are selected. If a subcategory is selected, then that portion of the tree is shown in full. My code adds “expand” and “collapse” links to the left side of each category that has subcategories.
Instructions
1. Install Category Checklist Tree plugin.
2. Download this code, save it to the root of your template folder and name it admin_category_stuff_js.js
3. In the functions.php file, add this at the end (this code will load the script whenever you are in the admin:
add_action(‘admin_init’, ‘admin_category_stuff’);
function admin_category_stuff() {
$template_url = get_bloginfo(‘template_url’);
wp_register_script(‘admin_category_stuff_js’,$template_url.’/admin_category_stuff_js.js’);
wp_enqueue_script(‘admin_category_stuff_js’);
}
That should do it! I welcome feedback on the code and will try to help you if you have trouble with it. I’ve tested in 3.0.x.



Works perfect! Thank you so much.
hi, i tried but i it doesn’t work maybe i didn’t understand will.
first i activate the plugin then put the script file in my theme/mytemplate/
and copy the script in function.php. but nothing happens…?
It seems you have understood the steps. Which version of WordPress are you using? Nothing happens at all?
works perfect in 3.2.1