WordPress.org

Support

Support » Plugins and Hacks » Non-linked Menu Item?

Non-linked Menu Item?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Janis Elsts
    Participant

    @whiteshadow

    You could enter a non-existent anchor in place of the URL, like “#abcde”.

    Hi Janis

    I’m trying to achieve this too but clicking on the parent will always link to the first child. If I create a child menu item with # as the URL, then the parent becomes a dummy link that opens the submenu when hovered over as wanted.

    There is no way it seems to have a hidden submenu item which acts as a dummy. Instead, the title can be left blank but this then adds a space at the top of the submenu.

    The only way I can think how to get around this with my knowledge is perhaps CSS.

    Thanks.

    Plugin Author Janis Elsts
    Participant

    @whiteshadow

    I’m trying to achieve this too but clicking on the parent will always link to the first child.

    That’s just how admin menus work in WordPress.

    There is no way it seems to have a hidden submenu item which acts as a dummy. Instead, the title can be left blank but this then adds a space at the top of the submenu.

    The only way I can think how to get around this with my knowledge is perhaps CSS.

    Yes, I don’t think there’s a way to do that with the WordPress admin menu API. You’ll have to hide the item with JS or CSS.

    I suppose I could add a special “Target page: None” option to the plugin that makes an item ignore clicks, but that still wouldn’t help with the hiding part. Normally WordPress will ignore hidden and inaccessible submenu items when deciding what the parent URL will be, which is not what you’d want in this case.

    The target none idea makes sense.

    As for the hiding of the child itme, would it be possible to have a checkbox in the child item which is linked to a css rule inside the plugin, i.e. if the checkbox is checked, then that particular item will be display:none.

    Looking at developer tools the style is #adminmenu .wp-submenu li.wp-first-item a.wp-first-item

    Cheers.

    I’ve noticed the CSS classes option in the parent which will help pinpoint the child css to display:none.

    Thanks.

    Here we are – this is inline styling but you could link to a stylesheet.

    function menu_child_hide() {
      echo '<style>
    #adminmenu .menu-child-hide .wp-submenu li.wp-first-item a.wp-first-item {
    display:none !important;
    }
      </style>';
    }

    I added the .menu-child-hide class in the parent, and so it wouldn’t link to it’s own page, I inserted # into the URL.

    Thanks.

    Plugin Author Janis Elsts
    Participant

    @whiteshadow

    The target none idea makes sense.

    It’s now on my to-do list and it will probably get implemented eventually.

    Here we are – this is inline styling but you could link to a stylesheet. […]

    That works for the first item. Hiding other submenus would be more complicated since you can’t change the class of a submenu item.

    I don’t suppose there’s a way to include a CSS classes option in each of the children as a get around?

    Plugin Author Janis Elsts
    Participant

    @whiteshadow

    Unfortunately, WordPress only lets you add custom CSS classes to top level menu items. To add that option for submenus, I’d have to either set the classes via JS (somehow), or replace the entire admin menu with a custom implementation written from scratch.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Non-linked Menu Item?’ is closed to new replies.