Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
// ...
function wpmm_init() {
$location = 'mega_menu';
$css_class = 'has-mega-menu';
$locations = get_nav_menu_locations();
if ( isset( $locations[ $location ] ) ) {
$menu = get_term( $locations[ $location ], 'nav_menu' );
if ( $items = wp_get_nav_menu_items( $menu->name ) ) {
foreach ( $items as $item ) {
if ( in_array( $css_class, $item->classes ) ) {
register_sidebar( array(
'id' => 'mega-menu-widget-area-' . $item->ID,
'name' => $item->title . ' - Mega Menu',
) );
}
}
}
}
}
add_action( 'widgets_init', 'wpmm_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.