[wp-trac] [WordPress Trac] #28620: When $depth argument is used in wp_nav_menu last level menu items still have .menu-item-has-children class, even though they are not shown
WordPress Trac
noreply at wordpress.org
Wed Jul 20 15:57:55 UTC 2022
#28620: When $depth argument is used in wp_nav_menu last level menu items still
have .menu-item-has-children class, even though they are not shown
--------------------------------------+------------------------
Reporter: slobodanmanic | Owner: chriscct7
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 6.1
Component: Menus | Version: 3.7
Severity: normal | Resolution:
Keywords: good-first-bug has-patch | Focuses: ui
--------------------------------------+------------------------
Changes (by petitphp):
* keywords: good-first-bug needs-testing has-patch => good-first-bug has-
patch
Comment:
The alternative patch looks good to me, I've refreshed it against trunk in
[https://core.trac.wordpress.org/attachment/ticket/28620/28620-alt.2.diff
28620-alt.2.diff].
Using a simple menu with two level of links and displaying it with
twentytwenty theme :
{{{
<ul id="menu-main-menu-2" class="menu">
<li class="menu-item menu-item-type-post_type menu-item-object-
page menu-item-has-children menu-item-5">
<a href="">Sample Page</a>
<span class="icon"></span>
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type
menu-item-object-post menu-item-has-children menu-item-6">
<a href="">Hello world!</a>
<span class="icon"></span>
<ul class="sub-menu">
<li class="menu-item menu-item-
type-taxonomy menu-item-object-category menu-item-8">
<a
href="">Uncategorized</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
}}}
When displaying the same menu with a custom `depth` argument :
**Before the patch**
The last element displayed has the `menu-item-has-children` class.
{{{
<div class="menu-main-menu-container">
<ul id="menu-main-menu-3" class="menu">
<li class="menu-item menu-item-type-post_type menu-item-
object-page menu-item-has-children menu-item-5">
<a href="">Sample Page</a><span
class="icon"></span>
<ul class="sub-menu">
<li class="menu-item menu-item-type-
post_type menu-item-object-post **menu-item-has-children** menu-item-6">
<a href="">Hello world!</a>
<span class="icon"></span>
</li>
</ul>
</li>
</ul>
</div>
}}}
**After the patch**
The class `menu-item-has-children` is not present anymore
{{{
<div class="menu-main-menu-container">
<ul id="menu-main-menu-3" class="menu">
<li class="menu-item menu-item-type-post_type menu-item-
object-page menu-item-has-children menu-item-5">
<a href="">Sample Page</a>
<span class="icon"></span>
<ul class="sub-menu">
<li class="menu-item menu-item-type-
post_type menu-item-object-post menu-item-6">
<a href="">Hello world!</a>
/li>
</ul>
</li>
</ul>
</div>
}}}
So working as expected.
I've also looked at the navigation block in Gutenberg but it doesn't seem
to use the existing code to render menu items so not sure if this patch
will affect it.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28620#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list