Make WordPress Core

Opened 7 weeks ago

Closed 11 hours ago

#62879 closed defect (bug) (fixed)

get_custom_logo does not apply the aria-current attribute in all cases

Reported by: bschneidewind's profile bschneidewind Owned by: audrasjb's profile audrasjb
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch commit
Focuses: accessibility Cc:

Description

When reading settings have a posts page set but not a page set for the homepage - get_custom_logo does not apply the aria-current attribute to the logo link on the homepage.

Attachments (2)

before-patch.png (88.8 KB) - added by shailu25 4 days ago.
Before Patch
after-patch.png (91.6 KB) - added by shailu25 4 days ago.
After Patch

Download all attachments as: .zip

Change History (22)

This ticket was mentioned in PR #8206 on WordPress/wordpress-develop by @bschneidewind.


7 weeks ago
#1

  • Keywords has-patch added

When reading settings have a posts page set but not a page set for the homepage - get_custom_logo does not apply the aria-current attribute to the logo link on the homepage.

Trac ticket: https://core.trac.wordpress.org/ticket/62879

#2 @audrasjb
7 weeks ago

  • Milestone changed from Awaiting Review to 6.8
  • Owner set to audrasjb
  • Status changed from new to reviewing

Hello, thanks for the ticket and the patch!
Self assigning for review.

@audrasjb commented on PR #8206:


7 weeks ago
#3

### Test report

Settings:

https://github.com/user-attachments/assets/5d6622b8-078c-456b-9888-b5efd8e29972

#### Before applying the PR: no aria-current attribute.

https://github.com/user-attachments/assets/bd4649ea-05e8-4093-b066-a75e0d1e11b1

#### After applying the PR: aria-current attribute displayed.

https://github.com/user-attachments/assets/405b9ef7-70a3-48f8-bf7f-a5bd407eb81e

### Test results

This PR fixes the issue 👍

#4 in reply to: ↑ description ; follow-up: @siliconforks
7 weeks ago

Replying to bschneidewind:

When reading settings have a posts page set but not a page set for the homepage

Some questions:

  1. Is that actually considered a valid, supported configuration (to have a posts page set but not a page set for the homepage)? That doesn't really seem like it would be useful combination of settings to me. I see that the WordPress admin section does in fact allow you to configure things that way, which is a bit odd and might be a bug?
  1. Assuming that this is a configuration that should be supported by WordPress, doesn't that imply that is_front_page() and WP_Query::is_front_page() are broken in that configuration? It appears that they will never return true in that configuration, which doesn't really make sense (obviously the site still has a front page).
  1. The current proposed changes to support this configuration involve adding some rather complex conditional logic. It is currently proposed that this logic be copied into multiple different places in the code?
  2. Copying this complex code into multiple places doesn't seem very DRY. Is this going to need to get copied into other places too? What about all the other themes besides twentytwenty? Fixing is_front_page() could perhaps eliminate the need for this.

#5 follow-up: @bschneidewind
7 weeks ago

@siliconforks - my thoughts on things:

1 - The UX already supports this in the admin area, I don't think it's the most logical approach overall but how could you force users to add a 'homepage' that may have already set it up this way? The render_block_core_home_link function already has support for this edge case as well.

2 - Agreed, it would be better if is_front_page always rang true when it's the root page but there are edge cases that need to be accounted for and there is some debate on whether is_front_page should remain true. Ex: if it's a paginated page... from an accessibility point it shouldn't, but the argument may differ in other aspects.

3 - This PR fixes get_custom_logo(). The TwentyTwenty update is to address the specific template function where the text version is missing the aria-current attribute. Yes, I am proposing this in multiple places to fix older themes and in core to address block based themes.

4 - I am proposing a similar approach be added in some of the older themes here where site logo support does not currently exist: #61766

Additional theme updates will be needed for bundled themes prior to TwentyTwentyTwo because of how things were built on each theme. Even if the is_front_page() was updated to account for the edge case, a theme update would be needed on those bundled themes that do not have support for aria-current on the site title links.

With TwentyTwentyTwo and up using block based approach, the aria-current attribute is applied correctly there on the text links for the site-title.

It does create some repeated code between TwentyTwentyOne and earlier bundled themes and the update to get_custom_logo, however I think it makes sense in these cases as the theme updates are only needed because of a different approach to building in TwentyTwentyOne and prior.

#6 @bschneidewind
7 weeks ago

Related, https://github.com/WordPress/wordpress-develop/pull/8237 - has been updated to account for all bundled themes (#62895)

#7 in reply to: ↑ 5 @siliconforks
7 weeks ago

Replying to bschneidewind:

Ex: if it's a paginated page... from an accessibility point it shouldn't, but the argument may differ in other aspects.

Yes, the pagination is another edge case, but the behavior of is_front_page() has always been to ignore pagination, so I'm not suggesting changing that here. I'm just proposing that is_front_page() handle the case where WordPress is configured without a page set for the homepage (assuming it is decided that this is actually a supported configuration).

Additional theme updates will be needed for bundled themes prior to TwentyTwentyTwo because of how things were built on each theme. Even if the is_front_page() was updated to account for the edge case, a theme update would be needed on those bundled themes that do not have support for aria-current on the site title links.

My point is that if is_front_page() is fixed, the theme update will be much simpler and require less duplicated code.

#8 @bschneidewind
7 weeks ago

@siliconforks - Good points - it's been discussed before it looks like #59252

I did throw a patch up to see if it gets anywhere and will adjust any other PR's if it makes progress.

#9 in reply to: ↑ 4 ; follow-ups: @sabernhardt
6 weeks ago

Is that actually considered a valid, supported configuration (to have a posts page set but not a page set for the homepage)? That doesn't really seem like it would be useful combination of settings to me.

The edge case might be fine to allow, but I do not think the special posts page should have aria-current (or current-menu-item classes) on home links.

When I assigned the page of posts without a static home page, the two URLs gave me duplicate content. With the Site Title block, I had the same link attributes at both URLs, too:

<p class="wp-block-site-title"><a href="http://localhost/wp671" target="_self" rel="home" aria-current="page">WP 6.7.1</a></p>

The home links' conditions for current-page ARIA and class names might need to check the URL (or $wp->request) instead of is_front_page() and/or is_home(). The logo link already adds aria-current incorrectly on the network signup and activation pages. Comments on #43536 note that wp-signup.php and wp-activate.php return true for both is_front_page() and is_home(), and is_home() potentially can return true as a fallback in other edge cases.

History for aria-current on home links:

  • [48749] get_custom_logo()
  • GB35880 Site Title block
  • GB51478 Home Link block

#10 in reply to: ↑ 9 @sabernhardt
6 weeks ago

I do not think the special posts page should have aria-current (or current-menu-item classes) on home links.

My first sentence was not highly appropriate on this ticket. The conditions in PR 8206 would add aria-current on the home page without adding the attribute on the extra page. However, the conditions might need changes for other cases.

#11 in reply to: ↑ 9 @siliconforks
6 weeks ago

Replying to sabernhardt:

Is that actually considered a valid, supported configuration (to have a posts page set but not a page set for the homepage)? That doesn't really seem like it would be useful combination of settings to me.

The edge case might be fine to allow, but I do not think the special posts page should have aria-current (or current-menu-item classes) on home links.

When I assigned the page of posts without a static home page, the two URLs gave me duplicate content. With the Site Title block, I had the same link attributes at both URLs, too:

<p class="wp-block-site-title"><a href="http://localhost/wp671" target="_self" rel="home" aria-current="page">WP 6.7.1</a></p>

Does this have anything to do with the edge case configuration, though? What happens if you do assign a static home page (in addition to a page of posts)? Won't you have the same issue on the posts page? (i.e., the link says aria-current="page" when it shouldn't)

This looks like it's a separate issue, with the Site Title block.

#12 @sabernhardt
6 weeks ago

Sorry, I have managed to make this quite confusing. Parts of comment:9 relate better to the Site Title and Home Link blocks.

Regarding get_custom_logo():

  1. The front-page conditions used in [48749] already created false positives for home logo links (and the unlink option) on the two network pages.
  2. Introducing an is_home() condition theoretically can add aria-current in unknown edge cases, though parse_query() corrects some situations in the lines following $this->is_home = true (so it might not be a major concern).

What happens if you do assign a static home page (in addition to a page of posts)?

The static home page would match is_front_page(), and aria-current is appropriate there (before or after PR 8206).

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


2 weeks ago

#14 @audrasjb
11 days ago

Hello, my opinion here is that the proposed changeset is not so complex (a one-line change) and that it's worth adding this fix even for such a edge case.

#15 @faisal03
11 days ago

The PR effectively fixes the issue, but considering that this is an edge case, it might be worth evaluating the performance implications before merging.

#16 @shailu25
4 days ago

Test Report

Patch Tested: https://github.com/WordPress/wordpress-develop/pull/8206

Environment:
WordPress - 6.8-alpha-20250202.040014
OS - Windows
Browser - Firefox
Theme: Twenty Twenty
PHP - 7.4.31
Active Plugin: None

Actual Results:

  • Issue Resolved With Patch.✅

Screenshots:

  • Added Attachment

@shailu25
4 days ago

Before Patch

@shailu25
4 days ago

After Patch

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


28 hours ago

#18 @audrasjb
28 hours ago

  • Keywords commit added

Marking this for commit.

@audrasjb commented on PR #8206:


12 hours ago
#19

Thanks for pushing the test cases @peterwilsoncc !

#20 @audrasjb
11 hours ago

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

In 60062:

General: Improve aria-current management in get_custom_logo().

This changeset fixes a edge case in get_custom_logo() where a page was set for the homepage without any front page in Settings > Reading and the aria-current attribute wasn't present on the logo link.

Props bschneidewind, audrasjb, siliconforks, sabernhardt, faisal03, shailu25, peterwilsoncc.
Fixes #62879.

Note: See TracTickets for help on using tickets.