Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link description support in Navigation Link block is needed #28446

Open
ndiego opened this issue Jan 23, 2021 · 0 comments
Open

Link description support in Navigation Link block is needed #28446

ndiego opened this issue Jan 23, 2021 · 0 comments

Comments

@ndiego
Copy link
Contributor

@ndiego ndiego commented Jan 23, 2021

What problem does this address?

In the Navigation Link block, there is a field for "Description" in the Link Settings. This was likely added to reflect the description field in the Menus link settings in non-FSE WordPress. Unfortunately, the current Description setting (attribute) does nothing, and there are no filters available in the render function of the block that would allow developers to add support for descriptions. So while the help text indicates that some themes might support descriptions, there does not appear to be a way (currently) for themes to actually support descriptions 😉

image

What is your proposed solution?

There are a couple solutions that I am happy to explore, but would like feedback from the community on the best path moving forward.

Option 1

In core themes, like Twenty Twenty One, link descriptions are not supported, but since the link output is filterable, developers can add support for descriptions as needed. Something as simple as the following would do the trick.

function prefix_nav_descriptions( $item_output, $item, $depth, $args ) {
    if ( ! empty( $item->description ) ) {
        $item_output = str_replace( $args->link_after . '</a>', $args->link_after . '</a><p class="menu-link_description">' . $item->description . '</p>', $item_output );
    }

    return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'prefix_nav_descriptions', 10, 4 );

The simplest approach would be to add similar filters to the navigation-link → index.php file. We could also provide a filter for the submenu icon so it could easily be swapped out. The current implementation is a bit of a headache if you want a different icon.

The problem with this approach is that all the modifications that are made via filters would not be available in the Site/Block Editor. So, while this would be the quickest solution, it is probably not ideal in the long run.

Option 2

An alternative approach would be to just make descriptions natively supported in the block. This would take more thought and design, but one implementation could looks something like this. Enabling link descriptions could also a setting in the theme.json file that theme developers could disable as needed.

image

The link description could also be its own block, but that might start getting too convoluted.

Let me know what everyone thinks, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant