6

I am building custom AdminModels based on Wagtail Snippets and have a custom menu in the AdminPanel for my models. How do I hide/remove the Snippet selection from AdminPanel without disabling? Thank you.

enter image description here

Charles Smith
  • 3,201
  • 4
  • 36
  • 80
  • Can u please put some code .. and my suggestion is to remove admin.site.register() which u want to remove – Jay Dave Feb 16 '17 at 09:55

2 Answers2

8

Since item.name in menu_items can be blank, better solution is:

from wagtail.snippets.wagtail_hooks import SnippetsMenuItem

@hooks.register('construct_main_menu')
def hide_snippets_menu_item(request, menu_items):
    menu_items[:] = [item for item in menu_items if not isinstance(item, SnippetsMenuItem)]
diveru4i
  • 103
  • 1
  • 6
  • 2
    I had an issue using the accepted answer because we use multiple names, depending on the user's language.. This solution is actually better – MatheusJardimB May 28 '21 at 00:02
7

Put the following hook into wagtail_hooks.py file of your Wagtail CMS app:

from wagtail.wagtailcore import hooks

@hooks.register('construct_main_menu')
def hide_snippets_menu_item(request, menu_items):
  menu_items[:] = [item for item in menu_items if item.name != 'snippets']

And you're basically done! You can use this approach to hide any item from the admin menu.

I described it recently on my blog: http://timonweb.com/posts/how-to-remove-snippets-menu-item-from-wagtail-cms-admin-menu/

timonweb
  • 338
  • 2
  • 3