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

Remove title attributes from Walker_Nav_Menu #7413

Conversation

sabernhardt
Copy link

Removes redundant tooltips from Walker_Nav_Menu::start_el()

Trac 51299


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Sep 23, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sabernhardt, joedolson.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@sabernhardt
Copy link
Author

51299.2.diff compared the title attribute against the item title, filtered only by the_title. If I had a good reason to compare before nav_menu_item_title three years ago, I did not explain it on the ticket, and I do not understand that decision today.

This PR now checks the title attribute after both the_title and nav_menu_item_title filters, and it still removes redundant tooltips before the nav_menu_link_attributes hook.

@joedolson
Copy link
Contributor

The value that is rendered is the version that's passed through both filters, and if we want to prevent duplicate values, we should generally pass through both filters.

However, Twenty Seventeen inserts an icon using the nav_menu_item_title filter. Other plugins and themes may do similar things. That will result in a difference in value, even though the accessible name may be unchanged.

Because of that, I'm wondering if we actually want to get those as two separate variables and compare against both of them, ignoring the title attribute if it matches either value.

@sabernhardt
Copy link
Author

Twenty Seventeen inserts an icon using the nav_menu_item_title filter.

That might be why I moved the comparison earlier in 51299.2.diff.

I'm wondering if we actually want to get those as two separate variables and compare against both of them, ignoring the title attribute if it matches either value.

Maybe. Switching trim() to wp_strip_all_tags() could be another option.

@joedolson
Copy link
Contributor

wp_strip_all_tags() would work for the twenty seventeen example, but there are potentially other cases it wouldn't work for. I'm imagining cases where people are inserting file extensions, screen reader text strings, where they're changing link texts dynamically based on the current user or logged in state, etc.

I think that the most valid use case of this attribute is where it definitely provides something other than the link text, and that shouldn't generally overlap with text that might be shown visually. I'd rather err in the direction of removing more title attributes than less.

@joedolson joedolson self-requested a review October 5, 2024 21:46
@joedolson
Copy link
Contributor

In r59177

@joedolson joedolson closed this Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants