Add Separators in WordPress Admin Menu


/ Published in: PHP
Save to your folder(s)

Add this snippet to theme's functions.php
Add menu items that will have separator after them to $separatorsAfter array.


Copy this code and paste it in your HTML
  1. add_action('admin_init', 'add_separators_admin_menu');
  2.  
  3. function add_separators_admin_menu()
  4. {
  5. //ADD SEPARATORS AFTER THESE MENU ITEMS
  6. $separatorsAfter = ['Media', 'Plugins', 'Settings', 'WooCommerce'];
  7. ///////////////////////////////////////
  8.  
  9. global $menu;
  10. if (is_admin()) {
  11. foreach((array) $separatorsAfter as $s){
  12. foreach ((array)$menu as $key => $item) {
  13. if (strpos($item[0], $s) !== false) {
  14. array_splice($menu, $key+1, 0, array(array(
  15. 0 => '',
  16. 1 => 'read',
  17. 2 => 'separator-last',
  18. 3 => '',
  19. 4 => 'wp-menu-separator'
  20. )));
  21. break;
  22. }
  23. }
  24. }
  25. }
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.