customization - Add a menu item to admin dashboard which isn't a link?

admin2025-06-02  1

This question already has answers here: Add a Separator to the Admin Menu? (7 answers) Closed 6 years ago.

I am trying to add a menu item which is supposed to be a separator which has a height set and divides items in the menu. I haven't managed to create a menu item which isn't a link.

add_action( 'admin_menu', 'add_admin_menu_separator' );
function add_admin_menu_separator()
{
    add_menu_page( '', '', 'read', 'test', '', 'none', '10000000' );
}

Doing this creates a menu item without any text or icon, but it is still a link to /test. Using # won't work either because I don't want it clickable at all.

Is there any workaround for this?

Thank you!

This question already has answers here: Add a Separator to the Admin Menu? (7 answers) Closed 6 years ago.

I am trying to add a menu item which is supposed to be a separator which has a height set and divides items in the menu. I haven't managed to create a menu item which isn't a link.

add_action( 'admin_menu', 'add_admin_menu_separator' );
function add_admin_menu_separator()
{
    add_menu_page( '', '', 'read', 'test', '', 'none', '10000000' );
}

Doing this creates a menu item without any text or icon, but it is still a link to /test. Using # won't work either because I don't want it clickable at all.

Is there any workaround for this?

Thank you!

Share Improve this question asked Mar 1, 2019 at 10:11 joq3joq3 3813 silver badges21 bronze badges 1
  • I'm not sure that this is the same thing? – joq3 Commented Mar 1, 2019 at 10:42
Add a comment  | 

1 Answer 1

Reset to default 0

You may want to look at adding admin style and then targeting the menu:

function admin_style() {
  wp_enqueue_style('admin-styles', get_template_directory_uri().'/admin.css');
}
add_action('admin_enqueue_scripts', 'admin_style');

This is just an example:

#menu-comments:before {
   border-top: 1px solid red;
   content: "";
   display: block;
   margin-top: 10px;
   margin-bottom: 10px;
   width: 100%;
}

This adds a red divider above the "comments" menu, but adjust this to your own requirements.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748851786a314254.html

最新回复(0)