I’d like to ask whether it’s possible to automatically remove or hide a menu item when the page it links to either doesn’t exist or is set to hidden.
To give more context: when adding a menu item via Content > Menus > [Menu Name] > Add menu item and linking it to a specific page, everything works as expected while the page is active. However, if that page is later deleted or set to hidden, the menu item remains visible and leads to an empty or broken link.
Would it be possible to detect the page’s status and prevent the menu item from appearing on the storefront when the page is unavailable?
You’d want to use something like this in your header.liquid file:
{% for link in linklists.main-menu.links %}
{% if link.type == 'http_link' or link.object != blank %}
<a href="{{ link.url }}">{{ link.title | escape }}</a>
{% endif %}
{% endfor %}
For hidden pages, I don’t believe there is a Liquid-native way to detect that status, so those menu items would still need to be removed manually from the Admin for now. Let me know if that works or if I can clarify anything more on our end here. Hope this helps!