Opened 8 years ago
Last modified 6 years ago
#39040 reopened enhancement
Hide references to nav menu locations that are not visible in the customizer preview
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.3 |
Component: | Customize | Keywords: | |
Focuses: | Cc: |
Description
Could be helpful to have menu locations automatically updated when switching template parts. For example if I have two header style:
header-singlemenu.php
<?php wp_nav_menu( array( 'theme_location' => 'primary', ));
header-doublemenu.php
<?php wp_nav_menu( array( 'theme_location' => 'primary-left', )); wp_nav_menu( array( 'theme_location' => 'primary-right', ));
Those got by
<?php get_template_part('header', get_theme_mod('header_style','singlemenu') ); ?>
where header_style obviously can be singlemenu or doublemenu
in functions.php i have
<?php if(get_theme_mod('header_style', 'singlemenu') == 'singlemenu') { register_nav_menu( 'primary', __( 'Primary Menu', 'theme-slug' ) ); } else { register_nav_menu( 'primary-left', __( 'Left Menu', 'theme-slug' ) ); register_nav_menu( 'primary-right', __( 'Right Menu', 'theme-slug' ) ); }
When switching header style in customizer, menu location are not updated. You are bound to save your customization, reload the page and then you can be able to see new location.
Change History (5)
#2
@
8 years ago
- Milestone changed from Awaiting Review to Future Release
- Summary changed from Refresh Menu Locations in Customizer after refresh to Hide references to nav menu locations that are not visible in the customizer preview
#3
@
8 years ago
- Resolution set to maybelater
- Status changed from new to closed
Thank you @westonruter for your answer. My test is exactly as you wrote with active callbacks, it work in the static part of customizer but if you want nav locations checkboxes toggled when switching a setting you need to have this:
$.each({ 'header_style': { controls: [ 'nav_menu_locations[primary]', 'nav_menu_locations[primary-left]', 'nav_menu_locations[primary-right]' ], aux: ['singlemenu', 'doublemenu', 'doublemenu'], callback: function(to, aux) { return aux === to; } } }, function(settingId, o) { api(settingId, function(setting) { $.each(o.controls, function(i, controlId) { api.control(controlId, function(control) { var visibility = function(to) { if ('aux' in o) { control.container.toggle(o.callback(to, o.aux[i])); } else { control.container.toggle(o.callback(to)); } }; visibility(setting.get()); setting.bind(visibility); }); }); }); });
So, this work but the problem is that could be useless to register nav menu locations for maybe using only one of these.
Finally, I think that nav_menu_location control should be organized/updated to support dynamic menu locations.
@khela thanks for the report. You raise an interesting use case. The best way to accomplish this right now would be to make use of the
active_callback
. This will get you most of the way:What this won't do is ensure that the nav menu location checkboxes are hidden when editing a nav menu in the customizer. This would need to be some additional JS that disables/hides those nav menu locations. Ideally this should all happen by default when a nav menu location is not available in the preview just like sections for widget sidebars not shown in the preview when they are not rendered.
This is also related to lazy-loading settings on demand: #28580.