Clean up empty parent folders after child page deactivation in AEM Cloud Sites
In Adobe Experience Manager (AEM) Cloud Sites, empty parent folders remain on Publish after child pages are unpublished. This behavior is out of the box. Use the workarounds below to remove the folders, stop new ones from accumulating, or hide them.
Description description
Environment
Adobe Experience Manager (AEM) Cloud Sites (all versions)
Symptoms
After unpublishing a child page from a folder structure, the parent folder (cq:Page node using a folder template) remains on the Publish environment as an empty or dangling shell. These folders often have no jcr:content and no child pages, but are still visible in the repository structure or search results on Publish.
Cause
This is the current out-of-the-box behavior in AEM Cloud Sites. Parent folders are retained on Publish to support the repository structure for child pages, but are not automatically removed when the last child page is unpublished. There is no out-of-the-box solution for automatic cleanup of these empty folders.
Resolution resolution
AEM has no out-of-the-box solution for empty parent folders that stay visible on Publish after child pages are unpublished. Use one or more of the following workarounds to remove them, stop new ones from accumulating, or hide them from search and navigation results.
- For a one-time cleanup of existing empty parent folders, use a Groovy script (for use with the AEM Groovy Console) to identify and deactivate empty folder pages on Author. Update the
rootPathin the script to the root of your site. Run the script on Author to deactivate any empty folder pages (cq:Pagenodes with no child pages) from Publish. - To prevent future accumulation, implement a custom replication event listener (for example, using an OSGi service) that listens for page deactivation events. After a page is deactivated, check if the parent folder is now empty (for example, has no child
cq:Pagenodes). If so, automatically deactivate the parent folder as well. - Exclude empty folders from search or navigation results on Publish to reduce confusion for content authors.
After running the cleanup script or deploying the event listener, verify on Publish that empty parent folders are no longer present in the repository structure or search results.