Remove all empty categories and sub-categories in Magento. When there are empty categories, the website shows an empty page in those categories in frontend. Create a file in the magento root, I will name it removeEmptyCats.php, with following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
require "app/Mage.php";
umask(0);
Mage::app();

$categoryCollection = Mage::getModel('catalog/category')->getCollection()
    ->addFieldToFilter('level', array('gteq' => 3)); //greater than root category id

foreach($categoryCollection as $category) {
    if ($category->getProductCount() === 0) {
        $category->delete();
    }
}

echo 'Empty Categories Deleted!';

Now you can easily run it by navigating to http://www.example.com/removeEmptyCats.php and wait for the message Empty Categories Deleted!

Note that this is going to DELETE those categories with have zero product count.