Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#52314 closed defect (bug) (fixed)

the HTML <title> tag for Edit Post should include the post's title

Reported by: skierpage's profile skierpage Owned by: joedolson's profile joedolson
Milestone: 5.9 Priority: normal
Severity: minor Version: 5.6
Component: Editor Keywords: has-patch has-screenshots commit
Focuses: accessibility, administration Cc:

Description

  1. Open wp-admin > Posts > All Posts
  2. Hover over a post then click Edit

RESULT:
The web page's <title> tag is just "Edit Post โ€น your blog name โ€” WordPress". There is no indication of what page you are editing. This makes it harder to later locate the tab in the browser, makes bookmarking posts you regularly edit harder, and the other problems of a poor web page title.

EXPECTED RESULT:
It would be nice to see part of the post's title in the web page's <title>, e.g. "Edit Post 'Britney Spearsโ€ฆ evar' โ€น your blog name โ€” WordPress"

VERSION: 5.6 in Firefox Nightly, running Linux on server and browser, using Gutenberg plug-in 9.7.0.

(This could be a bug in the Gutenberg editor rather than WordPress; there's code in src/wp-admin/edit.php to set the title:

$title = $post_type_object->labels->name;

but I'm not sure what it does.)

Attachments (10)

52314.diffโ€‹ (553 bytes) - added by audrasjb 3 years ago.
Here is a first try on this ticket :)
Capture dโ€™รฉcran 2021-05-10 ร  23.04.46.pngโ€‹ (166.4 KB) - added by audrasjb 3 years ago.
Result for a Page
Capture dโ€™รฉcran 2021-05-10 ร  23.05.18.pngโ€‹ (143.6 KB) - added by audrasjb 3 years ago.
Edge case: Result on a new Post without any Title for now
Capture dโ€™รฉcran 2021-05-10 ร  23.06.01.pngโ€‹ (191.8 KB) - added by audrasjb 3 years ago.
Result for a custom post type
52314-2.diffโ€‹ (783 bytes) - added by alexstine 3 years ago.
Fix for Untitled.
52314-3.diffโ€‹ (792 bytes) - added by sabernhardt 3 years ago.
translation updates, also re-using $post_title variable
52314-alternate.diffโ€‹ (597 bytes) - added by sabernhardt 3 years ago.
alternate option: keep existing Add New Post title, create the new Edit title when post is already published (even if untitled)
52314-4.diffโ€‹ (666 bytes) - added by sabernhardt 3 years ago.
'alternate' patch iteration, now checking for empty post title
52314-5.diffโ€‹ (1.2 KB) - added by sabernhardt 3 years ago.
using edit_item
52314.6.diffโ€‹ (1.7 KB) - added by SergeyBiryukov 3 years ago.

Download all attachments as: .zip

Change History (44)

#1 @SergeyBiryukov
4 years ago

  • Component changed from General to Editor
  • Focuses administration added

#2 follow-up: @alexstine
4 years ago

  • Type changed from defect (bug) to enhancement

@skierpage Thanks for submitting a ticket.

I am not 100% for sure, but I'd say the reason why this isn't included in core is because of the recommended length for the "title" tag. Please see here.

โ€‹https://www.w3.org/Provider/Style/TITLE.html

The title should ideally be less than 64 characters in length.

That being said, you are not out of options. There is a core filter called "admin_title" and you can use it to adjust this for the post screen.

โ€‹https://developer.wordpress.org/reference/hooks/admin_title/

Here's a small snippet that I wrote on my test site. Do not use this in production until testing to make sure it works well for you. It will generate a title that looks like this.

<title>Edit Post: Testing โ€น example.com โ€” WordPress</title>

This should work well across pages and posts. I tested using Classic Editor and Gutenberg.

add_filter( 'admin_title', 'change_admin_title_posts_screen', 10, 2 );
function change_admin_title_posts_screen( $admin_title, $title ) {
        global $post, $pagenow;
        if ( isset( $pagenow ) && 'post.php' == $pagenow ) { // Make sure we only change title on post.php
                $new_title = sprintf( __( '%1$s: %2$s &lsaquo; %3$s &#8212; WordPress' ),
                        $title, // Edit Post
                        $post->post_title, // Post title
                        get_bloginfo( 'name' ) // Blog title
                );
                return $new_title; // Return new title
        } else {
                return $admin_title; // Sanity line to return default title
        }
}

That is using the custom filter, you can add that snippet in a custom mu-plugin, plugin, or โ€‹child theme for testing.

I'd say if anything, this is likely an "Enhancement", not a "Bug." I could not replicate any difference between Classic Editor and Gutenberg in 5.6. Maybe others have an opinion on this?

Hope it helps. Thanks.

#3 in reply to: โ†‘ย 2 @skierpage
4 years ago

Replying to alexstine:
Thanks so much for responding and for the PHP code!

The title should ideally be less than 64 characters in length.

With a 14-character blog name, that still leaves 22 characters for the post title in "Edit Post 'Britney Spears greatesโ€ฆ' โ€น your blog name โ€” WordPress", excluding ellipsis. (My initial example truncated the middle of the post title, which is cool but probably overkill.) Also note the <title> of this Trac web page: it's 92 characters and includes the bug description because it's the right thing to do despite the W3C style guideline ๐Ÿ˜‰.

#4 @peterhartree
4 years ago

+1 to this issue: I hate to think how much time I've spent trying to find the correct "Edit post" tab over the years.

For what it's worth, my quick thought is that the following <title> format would be best for most people:

Edit: [Post name] < [Blog name] โ€” WordPress

I think we want as many words of the title as possible to be visible in the browser tab. Given that, including the post type (e.g. "Edit post:") does not seem above the bar.

For very long post names, it might make sense to truncate a bit. But I agree with @skierpageโ€”it seems fine to exceed the W3C 64 character recommendation in this case.

#5 @peterhartree
4 years ago

  • Focuses accessibility added

Seems like the status quo is especially bad for editors who rely on screen readersโ€”it could slow them down a bunch.

This ticket was mentioned in โ€‹Slack in #accessibility by ryokuhi. โ€‹View the logs.


4 years ago

#7 @joedolson
4 years ago

After discussion in the Accessibility team bug scrub, we're going to consider this a bug. While the current title can be argued to meet the requirements of WCAG 2.4.2 (โ€‹https://www.w3.org/WAI/WCAG21/Understanding/page-titled), by conveying the purpose of the page, it does not provide enough distinction to differentiate between multiple windows when those windows may be editing different posts.

It's a relatively minor issue, as it only impacts users working on multiple documents at once, but still an issue.

Noting that a final solution should probably include JS to monitor and react when the post title is changed in the editor.

#8 @alexstine
4 years ago

  • Milestone changed from Awaiting Review to 5.8
  • Owner set to alexstine
  • Status changed from new to accepted

This ticket was mentioned in โ€‹Slack in #accessibility by ryokuhi. โ€‹View the logs.


3 years ago

#10 @francina
3 years ago

  • Keywords needs-patch added

This ticket was mentioned in โ€‹Slack in #core by lukecarbis. โ€‹View the logs.


3 years ago

#12 @lukecarbis
3 years ago

  • Type changed from enhancement to defect (bug)

@audrasjb
3 years ago

Here is a first try on this ticket :)

#13 @audrasjb
3 years ago

  • Keywords has-patch added; needs-patch removed

@audrasjb
3 years ago

Edge case: Result on a new Post without any Title for now

@audrasjb
3 years ago

Result for a custom post type

#14 follow-up: @audrasjb
3 years ago

  • Keywords has-screenshots added

The title should ideally be less than 64 characters in length.

Maybe I'm wrong but I think this "rule" is only relevant for search engine optimization. If so, I think we don't really care about the length of the title of an admin page, isn't it? ๐Ÿ™‚

Last edited 3 years ago by audrasjb (previous) (diff)

@alexstine
3 years ago

Fix for Untitled.

#15 @alexstine
3 years ago

I just added patch: https://core.trac.wordpress.org/attachment/ticket/52314/52314-2.diff

In this patch, I changed the "Untitled" text to read "Add POST_TYPE_HERE". E.g. for a page it will read "Add Page".

Maybe this would look better than just "Edit Untitled" until we implement dynamic title updates via JS?

Thanks.

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


3 years ago

#17 @joedolson
3 years ago

  • Keywords needs-testing added

@sabernhardt
3 years ago

translation updates, also re-using $post_title variable

@sabernhardt
3 years ago

alternate option: keep existing Add New Post title, create the new Edit title when post is already published (even if untitled)

#18 @sabernhardt
3 years ago

I think 'Edit "Untitled"' is appropriate when a post is published without a title, so I made an additional option 52314-alternate.diffโ€‹.

  • If adding a new post, the title tag maintains the pre-existing "Add New Post" text.
  • If the post is already published, the new HTML title matches the aria-label for each Edit link that leads to the post editor.
  • If a published post does not have a title when the post editor loads, 'Edit "Untitled"' calls more attention to the missing title (without a formal error message).

However, if you disagree with me, 52314-3.patch simply includes some changes for translation: translating the "Untitled" string, plus matching the new Edit title to the aria-label text.

Version 0, edited 3 years ago by sabernhardt (next)

#19 @joedolson
3 years ago

I think 'untitled' is better, probably. In addition to the reasons @sabernhardt called out, it maintains contextual parity with how the title attribute is used when there is a title - the references are equivalent.

I will note that we can have both - there's no reason we can't use 'Edit {post_type} "Untitled"'.

In that case, I'd argue we should re-use the existing 'edit_item' string and append the post title. I don't think there's a translation issue here, since the 'edit_item' string is totally independent from the post title.

Thoughts?

@sabernhardt
3 years ago

'alternate' patch iteration, now checking for empty post title

#20 @sabernhardt
3 years ago

I'm unsure whether including the post type would help with a screen reader, though keeping the page title short would be better in the case of seeing multiple tabs (comment:4). (If we want to add the type, I don't know how to use the edit_item label.)

The post type was already included in the current, non-unique title. So the latest patch checks to verify the post title is not empty before replacing that version with Edit "" (in themes other than Twenty Twenty-One).

If a theme or plugin filters the title with a placeholder name, the new title tag uses that. With โ€‹Twenty Twenty-One's post title filter, a post published without entering a title would have Edit "Untitled" because "Untitled" is the main heading of the front-end page then.

#21 @audrasjb
3 years ago

  • Keywords needs-testing removed

The last proposal looks good to me. Are we fine with using that one for 5.8 @joedolson @sabernhardt? Or should it wait for the next release? I'm fine either way, but I think we're good to go as it :)

#22 @sabernhardt
3 years ago

@alexstine and Joe would have more valuable opinions than mine, but I'm content with my most recent patch 52314-4.diffโ€‹ :)

#23 @joedolson
3 years ago

I feel like we're losing the post type context if we shift to just the post title. It's certainly possible a user could be editing multiple posts with the same title but of different types, and it would be nice to be able to convey that in the title.

I think it benefits all users equally.

As far as the title length goes and how it's represented in the browser, screen reader users will have the full title read if they choose to hear it, as they aren't constrained to the visible text; other users will get what they get. In common cases, like pages or posts, it won't be that many additional characters.

In my personal browser use, it wouldn't make a difference either way...all I'm going to see is 'Edi'. :D

The edit item string is part of the post type label array: See: โ€‹https://developer.wordpress.org/reference/functions/get_post_type_labels/

#24 @hellofromTonya
3 years ago

  • Milestone changed from 5.8 to 5.9

Today is 5.8 Beta 1. As discussions are ongoing, punting to 5.9.

#25 @alexstine
3 years ago

At this point, how can we move this ticket forward? Still trying to decide on a patch or is it awaiting further testing? I personally do not have a preference. Whatever works the best, I'm good with.

Think we'll be able to land this for 5.9 and then get Gutenberg Issue open for dynamic JS updates?

@sabernhardt
3 years ago

using edit_item

#26 @sabernhardt
3 years ago

The ticket was waiting on another option, so I tried the edit_item label in 52314-5.diffโ€‹.

I like the simplicity of the previous patch, but now we have both methods to decide between them.

#27 @alexstine
3 years ago

I just tested 52314-5.diff and am happy with this patch. Think we can get this committed for 5.9 or is it already too late in the game?

I think it addresses all points. I get Edit Post/Edit Page followed by the title. Also, works for Add New Post/Add New Page. This should work fine for custom post types since this now uses labels.

Thanks.

#28 @audrasjb
3 years ago

  • Keywords commit added

The patch looks good to me as well in my tests. Marking for commit

#29 @joedolson
3 years ago

  • Owner changed from alexstine to joedolson

#30 @joedolson
3 years ago

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

In 51969:

Editor: Include post's title in editor title element.

Include the current post title in the title element when editing a post. Improve accessibility by distinguishing between different edit screens in the browser tab list.

Props skierpage, alexstine, audrasjb, sabernhardt.
Fixes #52314.

#31 in reply to: โ†‘ย 14 @SergeyBiryukov
3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to audrasjb:

The title should ideally be less than 64 characters in length.

Maybe I'm wrong but I think this "rule" is only relevant for search engine optimization. If so, I think we don't really care about the length of the title of an admin page, isn't it? ๐Ÿ™‚

I would suggest reconsidering this. The <title> tag on pretty much any other admin screen follows this format:

[screen title] โ€น [site title] โ€” WordPress

so it seems a bit inconsistent not to do the same on this screen. Titles can be longer than 64 characters, so we're not strictly following that recommendation anyway, and might as well keep using the same format for consistency.

See 52314.6.diffโ€‹.

#32 @joedolson
3 years ago

Good observation. For people managing multiple sites, knowing which site a post is in may be very relevant to context.

#33 @joedolson
3 years ago

  • Status changed from reopened to accepted

#34 @joedolson
3 years ago

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

In 52030:

Editor: Update structure of title element for editing.

Re-format the title element for post editing to follow general scheme for WordPress admin screens.

Props SergeyBiryukov.
Fixes #52314.

Note: See TracTickets for help on using tickets.