Removing nav_menu from custom page templates
-
Hello.
I’ve created a new custom page template for a child theme (parent theme is Hybrid).
This custom page template will be used for landing page and will need a less cluttered layout.
In my functions.php, I’ve already removed all widgets (I’ll see later if and which widget to put back), but I also need to remove all menus from this page: no navigations, no widget (yet), but just some layout and specific contents.
For the widgets, I’ve simply set the $sidebars_widgets to an empty array, but I don’t know what to do it with nav_menu objects/locations.
My last attempt is to hook a function to the ‘init’ action:
function landing_page_template_nav_menus() { if (is_page_template('page-landingpage.php')) { $locations = get_nav_menu_locations(); foreach ($locations as $location) { unregister_nav_menu($location); } } return $sidebars_widgets; }
Of course, this doesn’t work, most likely because the ‘init’ action doesn’t know yet the current page template.
I could try with other hooks (actually I did with some of them, without results), but I’d like to use the right one.Of course I could also play with CSS, but I prefer to have unused/unwanted html totally removed from the page source.
To clarify:
I want to write the code as if I’m unaware of all nav_menu locations (to make the code more reusable in other themes). That’s why I’m trying to use a loop.Bottom line, I need to find when to call this function, i.e. the right hook.
- The topic ‘Removing nav_menu from custom page templates’ is closed to new replies.