Opened 2 years ago
Last modified 2 years ago
#57313 new defect (bug)
Adding a menu item without a link URL should not add a broken HTML a tag
Reported by: | cliffpaulick | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.1.1 |
Component: | Menus | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
I just want a text-only menu item, but this adds an empty/broken <a> tag. See attached screenshot.
Attachments (2)
Change History (8)
#2
in reply to:
↑ 1
@
2 years ago
Replying to costdev:
I tested with Twenty Twenty-One and all plugins disabled and there was less markup but the
a
tag remained.
I then enabled Genesis child theme and the additional markup came through.
Sorry for the errant report here, but hopefully some bug fixing or enhancement results of it. Thanks for your efforts.
Thanks for opening this ticket @cliffpaulick!
Some info for those reading this ticket:
If the
a
element has nohref
attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.
The
target
,download
,ping
,rel
,hreflang
,type
, andreferrerpolicy
attributes must be omitted if thehref
attribute is not present.
If the
itemprop
attribute is specified on ana
element, then thehref
attribute must also be specified.
(my emphasis)
Source: HTML spec for <a> tag
- The link is invalid because it has an
itemprop
attribute, which requires anhref
attribute that isn't present.- I don't see this being added by Core anywhere, so I assume it's being added by a plugin or theme. In this case, the plugin/theme is failing to check the
href
value to determine whetheritemprop
should be added. If this is a bundled theme, we should correct this behaviour. If this is a third party theme/plugin, a ticket should be raised in the support forum for the plugin/theme.Aside from that, this is only possible because Core doesn't fully validate the
URL
field.
- Currently, you can't add an empty URL via
Appearance > Menus
or viaCustomize > Menus
.- However, on both screens, you can edit an existing link to remove the URL. i.e. Incomplete validation.
- I think this should be the focus for discussion on this ticket. Should we add this missing validation?
If there is a desire for Core to allow plain text menu items, this should be created as a separate
enhancement
ticket.
#3
@
2 years ago
@cliffpaulick I tested with Twenty Twenty-One and all plugins disabled and there was less markup but the a tag remained.
I then enabled Genesis child theme and the additional markup came through.
Thanks for additional information!
An empty <a>
tag without href
isn't invalid as mentioned by the HTML spec above - and, for example, could be targeted in CSS with a:not([href])
. It seems the Genesis theme adds the itemprop
attribute without checking whether doing so will produce an invalid <a>
tag. That's understandable, given that WordPress Core tries to block the possibility of an empty URL
in most cases.
The Menus
component considers an empty URL
field to be invalid and prevents it in all cases except when editing an existing menu item. I consider this a bug in Core, and think we should make the validation consistent.
#4
@
2 years ago
I agree empty a
tag is not invalid HTML. I like the idea of consistent validation but would then also like to see an enhancement ticket added for the ability to add plain text items to the menu, if you don't mind proceeding with both ends of this ticket as it is now. tyvm
Thanks for opening this ticket @cliffpaulick!
Some info for those reading this ticket:
(my emphasis)
Source: HTML spec for <a> tag
itemprop
attribute, which requires anhref
attribute that isn't present.href
value to determine whetheritemprop
should be added. If this is a bundled theme, we should correct this behaviour. If this is a third party theme/plugin, a ticket should be raised in the support forum for the plugin/theme.Aside from that, this is only possible because Core doesn't fully validate the
URL
field.Appearance > Menus
or viaCustomize > Menus
.If there is a desire for Core to allow plain text menu items, this should be created as a separate
enhancement
ticket.