Skip to content

Navigation block: Hiding a link item breaks the HTML into two separate lists #78784

Closed

Description

@coreyworrell

Description

I hid one of the links inside the navigation block, and on the frontend it shows two <ul> elements, one with all menu items up to the hidden link, and the next with all items after the hidden link. This affects styling.

I noticed it on our site because our menu uses CSS multi-column layout, and the menu items after the hidden item were below on their own line instead of in the usual flow.

Step-by-step reproduction instructions

  1. Add navigation block.
  2. Add several items to navigation block.
  3. Use the new block visibility feature to hide one of the items.
  4. View frontend and see menu has two <ul>s now.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 7.0

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. vedant-ere commented on May 29, 2026

    @vedant-ere
    Contributor

    I can reproduce this on WordPress 7.0 with Gutenberg active.

    Hiding a middle navigation item results in two separate <ul class="wp-block-navigation__container">
    elements in the DOM one containing items before the hidden block,
    one containing items after it.

    Looking into the Navigation block's render logic for a fix.

  2. vedant-ere commented on May 29, 2026

    @vedant-ere
    Contributor

    Root cause identified:

    In WP_Navigation_Block_Renderer::get_inner_blocks_html(), the loop tracks list state using an $is_list_open flag. When a block is hidden via block visibility, $inner_block->render() returns an empty string ''. WP_HTML_Tag_Processor finds no <li> in the empty string, so $is_list_item is false. This satisfies the close condition ! $is_list_item && $is_list_open, closing the <ul> prematurely. The next visible item then opens a brand new <ul>, producing two separate lists.

    Fix: Added an early continue to skip empty block markup inside the foreach loop, preserving the $is_list_open state across hidden blocks:

    if ( '' === $inner_block_markup ) {
        continue;
    }

    PR attached in #78793.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions