how to group custom post types

The filter

Inside /wp-admin/menu.php, you’ll find this filter at the end of the “add css classes”-loop:
apply_filters( 'add_menu_classes', $menu )

The function

The following code attaches the right classes to the first and previous elements. It also adds the separator in between. If you need to add another separator to the end/after your group, you’ll have to extend the function to do the following:

  • Take the last element in your group and treat it exactly as you currently treat your previous element.
  • Add the separator one key after your last element
  • Add the same classes to the following/next element right after your group
  • Check if there’s not already a separator in place. See current check.

Use the $target array to look up for the names of the targeted menu elements. Just use exactly what you see in your menu and it adds a separator before the element.


Moved the code to GitHub as public Gist

Leave a Comment