Use Wagtail CMS Snippets but Hide in Admin Panel
Asked Answered
S

2

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

Subtorrid answered 16/2, 2017 at 2:8 Comment(1)
Can u please put some code .. and my suggestion is to remove admin.site.register() which u want to removePestle
C
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/

Coroner answered 16/2, 2017 at 13:59 Comment(1)
Awesome! Thank You.Subtorrid
G
9

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)]
Greaves answered 25/6, 2020 at 9:34 Comment(1)
I had an issue using the accepted answer because we use multiple names, depending on the user's language.. This solution is actually betterGaunt
C
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/

Coroner answered 16/2, 2017 at 13:59 Comment(1)
Awesome! Thank You.Subtorrid

© 2022 - 2025 — McMap. All rights reserved.