I am trying to create an admin menu separator that allows you to put them in with code. This is the function:
function add_admin_menu_separator($position) {
global $menu;
$index = 0;
foreach($menu as $offset => $section) {
if (substr($section[2],0,9)=='separator')
$index++;
if ($offset>=$position) {
$menu[$position] = array('','read',"separator{$index}",'','wp-menu-separator');
break;
}
}
ksort( $menu );
}
The add action bit is below
add_action('admin_init','admin_menu_separator');
function admin_menu_separator() {
add_admin_menu_separator(220);
}
It works okay but it produces the following errors in WordPress when rearranging menus:
> Warning: Invalid argument supplied for foreach() in /home/user/public_html/wp-creation.com/wp-content/themes/liquid_theme_0.4_licensed/functions.php on line 174
> Warning: ksort() expects parameter 1 to be array, null given in /home/user/public_html/wp-creation.com/wp-content/themes/liquid_theme_0.4_licensed/functions.php on line 182
Adding WordPress Menu Separator In the Custom links block add a new menu item with the same name. Add # hash symbol. Add # hash symbol into the link field to create a non-clickable menu item. Click on Add to Menu button to add the non-clickable item (separator) to your existing menu.
You should hook in admin_menu
:
add_action('admin_menu','admin_menu_separator');
And use something lower than 220
. The biggest offset
I got in my system is 99
.
Check this very fine class to deal with Admin Menus.
It appeared in this WPSE Question: Add a Separator to the Admin Menu?
You can simply add this in functions.php
add_action('admin_menu', function () {
global $menu;
$menu[49] = ['', 'read', '', '', 'wp-menu-separator'];
});
Where 49 is separator position, You have to remember that separator position can replace your menu element if it has the same position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With