<?php
// Define HTML structure of Footer Menu
$args = array (
'footer-menu' => 'footer-menu',
'menu_class' => 'nav',
'menu_id' => 'menu-main-menu',
'container' => false,
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'
);
?>
<footer>
<p id="colophon">Copyright © 2019 Around After Dark. All rights reserved.</p>
<?php wp_nav_menu( array( $args ) ); ?>
</footer>
<?php wp_footer(); ?>
</body>
</html>
The output still wraps the ul
within a div
.
I use WP_nav_menu to output some menus in footer. Each menu link is styled with help of certain class which is assigned like shown in code below. But when plugin is active, certain class is removed and style is absent. Is there a way to stop plugin doing it or maybe a some override?
<?php
wp_nav_menu(
array (
'theme_location' => 'footer_for_customer',
'menu' => 'footer_for_customer',
'menu_class' => 'menu-list',
'container' => 'div',
'container_class' => 'col-12 col-md-4 col-lg-3 order-first',
'before' => '<li class="menu-list__item">',
'after' => '</li>',
'link_class' => 'menu-list__link',
)
);
?>
]]> <ul class="nav-primary__list accordion" data-accordion data-multi-expand="false" data-allow-all-closed="true">
<li class="nav-primary__item accordion-item" data-accordion-item>
<a href="#nav-primary-0" class="nav-primary__heading accordion-title">
<span class="nav-primary__label">Academics</span>
<span class="trigger">
<svg class="brei-icon brei-icon-plus" focusable="false">
<use xlink:href="#brei-icon-plus"></use>
</svg>
<svg class="brei-icon brei-icon-minus" focusable="false">
<use xlink:href="#brei-icon-minus"></use>
</svg>
</span>
</a>
<div class="nav-primary__content accordion-content" data-tab-content id="nav-primary-0">
<a href="#" class="nav-primary__self">Academics <svg class="brei-icon brei-icon-triple-chevron" focusable="false" viewBox="0 0 45.2 32">
<path class="chevron-1" d="M15.6,14.6L3.2,0L0,2.7L11.3,16L0,29.3L3.2,32l13.6-16L15.6,14.6z"/>
<path class="chevron-2" d="M29.8,14.6L17.4,0l-3.2,2.7L25.5,16L14.2,29.3l3.2,2.7L31,16L29.8,14.6z"/>
<path class="chevron-3" d="M44,14.6L31.5,0l-3.2,2.7L39.7,16L28.4,29.3l3.2,2.7l13.6-16L44,14.6z"/>
</svg>
</a>
<ul class="nav-primary__children">
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum on Two Lines</span>
</a>
</li>
</ul>
</div>
</li>
<li class="nav-primary__item accordion-item" data-accordion-item>
<a href="#nav-primary-1" class="nav-primary__heading accordion-title">
<span class="nav-primary__label">Cost And Aid</span>
<span class="trigger">
<svg class="brei-icon brei-icon-plus" focusable="false">
<use xlink:href="#brei-icon-plus"></use>
</svg>
<svg class="brei-icon brei-icon-minus" focusable="false">
<use xlink:href="#brei-icon-minus"></use>
</svg>
</span>
</a>
<div class="nav-primary__content accordion-content" data-tab-content id="nav-primary-1">
<a href="#" class="nav-primary__self">Cost And Aid <svg class="brei-icon brei-icon-triple-chevron" focusable="false" viewBox="0 0 45.2 32">
<path class="chevron-1" d="M15.6,14.6L3.2,0L0,2.7L11.3,16L0,29.3L3.2,32l13.6-16L15.6,14.6z"/>
<path class="chevron-2" d="M29.8,14.6L17.4,0l-3.2,2.7L25.5,16L14.2,29.3l3.2,2.7L31,16L29.8,14.6z"/>
<path class="chevron-3" d="M44,14.6L31.5,0l-3.2,2.7L39.7,16L28.4,29.3l3.2,2.7l13.6-16L44,14.6z"/>
</svg>
</a>
<ul class="nav-primary__children">
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum on Two Lines</span>
</a>
</li>
</ul>
</div>
</li>
<li class="nav-primary__item accordion-item" data-accordion-item>
<a href="#nav-primary-2" class="nav-primary__heading accordion-title">
<span class="nav-primary__label">Admissions</span>
<span class="trigger">
<svg class="brei-icon brei-icon-plus" focusable="false">
<use xlink:href="#brei-icon-plus"></use>
</svg>
<svg class="brei-icon brei-icon-minus" focusable="false">
<use xlink:href="#brei-icon-minus"></use>
</svg>
</span>
</a>
<div class="nav-primary__content accordion-content" data-tab-content id="nav-primary-2">
<a href="#" class="nav-primary__self">Admissions <svg class="brei-icon brei-icon-triple-chevron" focusable="false" viewBox="0 0 45.2 32">
<path class="chevron-1" d="M15.6,14.6L3.2,0L0,2.7L11.3,16L0,29.3L3.2,32l13.6-16L15.6,14.6z"/>
<path class="chevron-2" d="M29.8,14.6L17.4,0l-3.2,2.7L25.5,16L14.2,29.3l3.2,2.7L31,16L29.8,14.6z"/>
<path class="chevron-3" d="M44,14.6L31.5,0l-3.2,2.7L39.7,16L28.4,29.3l3.2,2.7l13.6-16L44,14.6z"/>
</svg>
</a>
<ul class="nav-primary__children">
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum on Two Lines</span>
</a>
</li>
</ul>
</div>
</li>
<li class="nav-primary__item accordion-item" data-accordion-item>
<a href="#nav-primary-3" class="nav-primary__heading accordion-title">
<span class="nav-primary__label">Student and Campus Life</span>
<span class="trigger">
<svg class="brei-icon brei-icon-plus" focusable="false">
<use xlink:href="#brei-icon-plus"></use>
</svg>
<svg class="brei-icon brei-icon-minus" focusable="false">
<use xlink:href="#brei-icon-minus"></use>
</svg>
</span>
</a>
<div class="nav-primary__content accordion-content" data-tab-content id="nav-primary-3">
<a href="#" class="nav-primary__self">Student and Campus Life <svg class="brei-icon brei-icon-triple-chevron" focusable="false" viewBox="0 0 45.2 32">
<path class="chevron-1" d="M15.6,14.6L3.2,0L0,2.7L11.3,16L0,29.3L3.2,32l13.6-16L15.6,14.6z"/>
<path class="chevron-2" d="M29.8,14.6L17.4,0l-3.2,2.7L25.5,16L14.2,29.3l3.2,2.7L31,16L29.8,14.6z"/>
<path class="chevron-3" d="M44,14.6L31.5,0l-3.2,2.7L39.7,16L28.4,29.3l3.2,2.7l13.6-16L44,14.6z"/>
</svg>
</a>
<ul class="nav-primary__children">
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum on Two Lines</span>
</a>
</li>
</ul>
</div>
</li>
<li class="nav-primary__item accordion-item" data-accordion-item>
<a href="#nav-primary-4" class="nav-primary__heading accordion-title">
<span class="nav-primary__label">About Taft College</span>
<span class="trigger">
<svg class="brei-icon brei-icon-plus" focusable="false">
<use xlink:href="#brei-icon-plus"></use>
</svg>
<svg class="brei-icon brei-icon-minus" focusable="false">
<use xlink:href="#brei-icon-minus"></use>
</svg>
</span>
</a>
<div class="nav-primary__content accordion-content" data-tab-content id="nav-primary-4">
<a href="#" class="nav-primary__self">About Taft College <svg class="brei-icon brei-icon-triple-chevron" focusable="false" viewBox="0 0 45.2 32">
<path class="chevron-1" d="M15.6,14.6L3.2,0L0,2.7L11.3,16L0,29.3L3.2,32l13.6-16L15.6,14.6z"/>
<path class="chevron-2" d="M29.8,14.6L17.4,0l-3.2,2.7L25.5,16L14.2,29.3l3.2,2.7L31,16L29.8,14.6z"/>
<path class="chevron-3" d="M44,14.6L31.5,0l-3.2,2.7L39.7,16L28.4,29.3l3.2,2.7l13.6-16L44,14.6z"/>
</svg>
</a>
<ul class="nav-primary__children">
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum</span>
</a>
</li>
<li class="nav-primary__child">
<a href="#" class="menu-secondary">
<span class="text">Child Page Lorem Ipsum on Two Lines</span>
</a>
</li>
</ul>
</div>
</li>
</ul>
And this is about as far as I’ve gotten trying to replicate it from examples I’ve grabbed from various locations.
class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
/**
* Starts the list before the elements are added.
*
* Adds classes to the unordered list sub-menus.
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args An array of arguments. @see wp_nav_menu()
*/
function start_lvl( &$output, $depth = 0, $args = array() ) {
// Depth-dependent classes.
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
$classes = array(
'nav-primary__children',
( $display_depth % 2 ? 'menu-odd' : 'menu-even' ),
( $display_depth >=2 ? 'sub-sub-menu' : '' ),
'menu-depth-' . $display_depth
);
$class_names = implode( ' ', $classes );
// Build HTML for output.
$output .= "\n" . $indent . '<div class="nav-primary__content accordion-content" data-tab-content id="nav-primary-0"><a href="#" class="nav-primary__self">Academics <svg class="brei-icon brei-icon-triple-chevron" focusable="false" viewBox="0 0 45.2 32"><path class="chevron-1" d="M15.6,14.6L3.2,0L0,2.7L11.3,16L0,29.3L3.2,32l13.6-16L15.6,14.6z"/><path class="chevron-2" d="M29.8,14.6L17.4,0l-3.2,2.7L25.5,16L14.2,29.3l3.2,2.7L31,16L29.8,14.6z"/><path class="chevron-3" d="M44,14.6L31.5,0l-3.2,2.7L39.7,16L28.4,29.3l3.2,2.7l13.6-16L44,14.6z"/> </svg></a><ul class="' . $class_names . '" >' . "\n";
}
/**
* Start the element output.
*
* Adds main/sub-classes to the list items and links.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args An array of arguments. @see wp_nav_menu()
* @param int $id Current item ID.
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
// Depth-dependent classes.
$depth_classes = array(
( $depth == 0 ? 'nav-primary__item accordion-item' : '' ),
( $depth >=2 ? 'nav-primary__child' : '' ),
( $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ),
'menu-item-depth-' . $depth
);
$depth_class_names = esc_attr( implode( ' ', $depth_classes ) );
// Passed classes.
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );
// Build HTML.
$output .= $indent . '<li id="nav-menu-item-'. $item->ID . '" class="' . $depth_class_names . ' ' . $class_names . '">';
// Link attributes.
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$attributes .= ' class="nav-primary__heading ' . ( $depth > 0 ? 'sub-menu-link' : 'accordion-title' ) . '"';
// Build HTML output and pass through the proper filter.
$item_output = sprintf( '%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
$args->before,
$attributes,
$args->link_before,
apply_filters( 'the_title', $item->title, $item->ID ),
$args->link_after,
$args->after
);
$output .= '<!-- Outception -->';
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
function end_el( &$output, $data_object, $depth = 0, $args = null ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$output .= "<!--</div>-->{$n}";
}
}
At this point I would love to consider removing the stupid second level all together, but that’s half ass and I want to whole ass the project.
Can anyone shed some light on how to properly re-create this stupid menu?
Hoping for some advice from the awesome WP community.
On my local server, I have WP 6.02 installed, and everything works great. On my online “staging” site, I also have 6.02 installed, but something ain’t working right with wp_nav_menu(). Here is the relevant code in my header.php file:
<div id='nav_menu-container' class='nav_menu-container'>
<?php
if ( has_nav_menu( 'main' )) {
wp_nav_menu( [
'menu' => 'Main Menu',
'theme_location' => 'top',
'container' => 'nav',
'container_id' => 'main_menu-container',
'menu_id' => 'main_menu',
'menu_class' => 'main_menu',
]);
}
americancyanide_login_menu();
?>
</div>
I have assigned a class to the nav container of main_menu-container. The generated UL is then supposed to get the ‘main_menu’ id and class. Again, on my local server, works perfect, but on my online version, the main_menu class is put on the nav container, thus rendering the CSS rules useless.
Have I forgotten to do something?
]]>after the update my menus stopped to work – only “Add item” instead of whole menu is shown.
Just because of the update nothing else was done (automatically without my attention obviously).
I am using in my own theme a “wp_nav_menu” called for a menu name.
`wp_nav_menu( array(
‘menu’ => ‘Menu’,
‘depth’ => 5,
‘container’ => ‘ul’,
‘container_class’ => ”,
‘menu_class’ => ‘navbar-nav ml-auto my-2 my-lg-0 ‘,
‘fallback_cb’ => ‘wp_bootstrap_navwalker::fallback’,
‘walker’ => new wp_bootstrap_navwalker()
));
calling menu by name or by theme location completely stopped to work.
– menu calling by name does not work, no entries
– calling menu by theme_location no entries
– if I delete all atributes then it returns all possible menu items ignoring created menus
– fallback and walker itself when enabled then returns no entry
FIXED by :
– force downgrade to 5.9.3
This itself does not fix this, I needed to switch to another theme 2020 and then back to my and it was back again
Please fix this ASAP
]]>The output I’m looking for is:
<nav class="nav">
<ul>
<li>
<a href="#">Campers<span class="js-trigger-dropdown"><i class="fas fa-sort-down"></i></span></a>
<div class="dropdown">
<ul>
<li>
<a href="#">
<div class="dropdown__image"><img src="assets/images/temp/[email protected]" alt=""></div>
<div class="dropdown__content">
<h6>Volkswagen T2b</h6>
<p>Rood</p>
</div>
</a>
</li>
</ul>
</div>
</li>
<li><a href="#">Over evan</a></li>
<li><a href="#">Blog</a></li>
<li>
<a href="#">
Help<span class="js-trigger-dropdown"><i class="fas fa-sort-down"></i></span>
</a>
<div class="dropdown dropdown--secondary">
<ul>
<li><i class="fas fa-arrow-right"></i><a href="#">Contact</a></li>
<li><i class="fas fa-arrow-right"></i><a href="#">Routebeschrijving</a></li>
<li><i class="fas fa-arrow-right"></i><a href="#">FAQ</a></li>
</ul>
</div>
</li>
</ul>
</nav>
You can see that the two submenu levels have a slightly different output.
The Walker class i’m currently working with is:
class CSS_Menu_Maker_Walker extends Walker {
var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
function start_lvl( &$output, $depth = 0, $args = array(), $top_level_elements = array() ) {
$indent = str_repeat( "\t", $depth );
if ($args->walker->has_children) {
$output .= "\n$indent<div class=\"dropdown\"><ul>\n";
} else {
$output .= "\n$indent<ul>\n";
}
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
if ($args->walker->has_children) {
$output .= "$indent</div></ul>\n";
} else {
$output .= "$indent</ul>\n";
}
}
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
/* Add active class */
if(in_array('current-menu-item', $classes)) {
$classes[] = 'active';
unset($classes['current-menu-item']);
}
/* Check for children */
$children = get_posts(array('post_type' => 'nav_menu_item', 'nopaging' => true, 'numberposts' => 1, 'meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $item->ID));
if (!empty($children)) {
$classes[] = 'has-sub';
}
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
//$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$class_names = $class_names ? '' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
if ($args->walker->has_children) {
$item_output .= '<span class="js-trigger-dropdown"><i class="fas fa-sort-down"></i></span></a>';
} else {
$item_output .= '</a>';
}
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
function end_el( &$output, $item, $depth = 0, $args = array() ) {
$output .= "</li>\n";
}
}
Looking forward to getting some help
i’m learning to build themes from scratch and following theme handbook awa codex.
i can’t display the menu i’ve coded in my theme files and the pages i’ve added to that menu.
i have theme unit test data installed which comes with 3 menu locations: long, testing, and empty.
when i added code below, i got what i believe is the testing menu. i can see my menus in customizer and admin, but i can’t get my Main Menu to display.
register_nav_menus(
array(
'main_menu' => __( 'Main Menu', 'namespace' ),
'footer_menu' => __( 'Footer Menu', 'namespace' ),
'social_menu' => __( 'Social Menu', 'namespace' ),
)
);
wp_nav_menu(
array(
'theme_location' => 'main-menu',
'container' => 'div',
'container_class' => 'main-nav',
'container_id' => 'main-menu',
)
);
selecting my menu location doesn’t work. making a new menu and selecting my menu location doesn’t work. i don’t think deleting the TUT menus is the point of the data so i haven’t done that.
also, the container class/id isn’t showing on the menu that does display on the site which leads me to believe it’s not using my menu, but idk.
thanks,
Believe me when I say I’ve searched for a solution for this. I’ve tried numerous code snippets but none have worked.
I have a custom post type of ‘news’ with ‘archive-news.php’ and ‘single-news.php’. When I add post type menu archive item to the main menu and visit the news archive page ‘News’ is highlighted in the menu using the ‘mega-current-menu-item’ class.
When I click on a news article post the URL changes from domain.com/news to domain.com/news/article-title but news link isn’t highlighted anymore.
I can’t find a solution that will add the ‘mega-current-menu-item’ class to the News menu item when view the news article.
Hope this makes sense and someone can point me in the right direction.
Thanks
Wayne.
]]>