WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#33775 closed defect (bug) (fixed)

comment_form() Leave a Reply heading level can't be changed

Reported by: afercia Owned by: afercia
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.3
Component: Comments Keywords: has-patch commit
Focuses: accessibility Cc:

Description

When using comment_form() to output the complete comment form, the "Leave a Reply" heading is assumed to be a <h3> and there's no way to change the heading level. See the screenshot below, it's the heading structure in Twenty Sixteen.

  • when there are comments: the headings hierarchy doesn't miss levels but I'd say the <h3> should be a <h2> anyways
  • when there are no comments yet, there's a missing heading level

Assuming a <h3> will be always a correct heading level it's just... well an assumption. IMHO, functions that output HTML should always give the ability to filter the output or set the relevant part of the HTML using arguments.

https://cldup.com/fbN5cHtvmO.png

Attachments (1)

33775.patch (2.4 KB) - added by tyxla 2 years ago.
In comment_form(): implement title_reply_before and title_reply_after args to allow modifying the HTML of the comment form reply title.

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in Slack in #core-themes by afercia. View the logs.


2 years ago

#2 @wonderboymusic
2 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to afercia
  • Status changed from new to assigned

#3 @tyxla
2 years ago

Cool idea.

I suggest that we implement that by adding 2 additional comment_form() args: title_reply_before and title_reply_after.

This would allow the user to:

  • Specify these args when calling comment_form();
  • Filter the default arg values, using the comment_form_defaults filter;
  • Completely modify the reply title HTML, not only the heading - sometimes the ID or class might need to be altered.

Patch coming up.

@tyxla
2 years ago

In comment_form(): implement title_reply_before and title_reply_after args to allow modifying the HTML of the comment form reply title.

#4 @tyxla
2 years ago

  • Keywords has-patch added

#5 @afercia
2 years ago

Ideally, to avoid the missing heading level, the default should be a <h2>. I fear we can't change that for backwards compatibility but maybe we should consider to use what @tyxla suggested and make it a <h2> in the bundled themes, starting with Twenty Sixteen. Also to inform and educate theme authors. Below, the current situation keeping the <h3> as default:

https://cldup.com/GttBTtXO5u.png

A <h2> would make sense in both cases and would allow to keep it simple (no conditionals). Thoughts? cc @iamtakashi @obenland

#6 follow-up: @obenland
2 years ago

Yeah, we can't change it to an <h2> by default. We could possibly make it an h2/h3 based on whether the post has comments or not. Just a quick thought, not fully thought through.

#7 in reply to: ↑ 6 @afercia
2 years ago

  • Keywords commit added

Replying to obenland:

We could possibly make it an h2/h3 based on whether the post has comments or not. Just a quick thought, not fully thought through.

Yeah, was thinking to keep it simple and just change it (via arguments) in h2 without any check/conditional. Thoughts about the patch? I'd say commit consideration. :)

#8 @wonderboymusic
2 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34308:

Add title_reply_before and title_reply_after args to comment_form() to allow the "Leave a Reply" heading level to be changed.

Props tyxla.
Fixes #33775.

Note: See TracTickets for help on using tickets.