Posts list: show part of excerpt in Compact view if post has no title#11553
Posts list: show part of excerpt in Compact view if post has no title#11553sabernhardt wants to merge 5 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| .trimmed-post-excerpt { | ||
| font-weight: 400; | ||
| padding-left: 4px; | ||
| } |
| * | ||
| * @param WP_Post $item The current WP_Post object. | ||
| */ | ||
| public function column_cb( $item ) { |
There was a problem hiding this comment.
The checkbox label should include the same text as the link (with 'Select').
The locked icon text might not require the same, but I updated that anyway.
| if ( 'excerpt' !== $mode && '' === get_the_title( $post ) && ! post_password_required( $post ) ) { | ||
| $excerpt = get_the_excerpt( $post ); | ||
| if ( '' !== $excerpt && is_string( $excerpt ) ) { | ||
| $title .= ' <span class="trimmed-post-excerpt">' . esc_html( wp_trim_words( $excerpt, 15, ' …' ) ) . '</span>'; |
There was a problem hiding this comment.
Escapes the output even though wp_trim_words() strips all tags, because it also has a wp_trim_words filter.
|
Tested via Playground and this works as expected for Posts and Pages, noting the excerpt/first bit of page content shows only on the Compact view and not on the Extended view. |
mcsf
left a comment
There was a problem hiding this comment.
Thanks for the patch, this is looking great. I've left some notes.
| if ( 'excerpt' !== $mode && '' === get_the_title( $post ) && ! post_password_required( $post ) ) { | ||
| $excerpt = get_the_excerpt( $post ); | ||
| if ( '' !== $excerpt && is_string( $excerpt ) ) { | ||
| $title .= ' <span class="trimmed-post-excerpt">' . esc_html( wp_trim_words( $excerpt, 15, ' …' ) ) . '</span>'; |
There was a problem hiding this comment.
About the $more string:
- Why the leading space? In my mind a simple
'…'makes the most sense, and this seems to be corroborated by the many priors in the codebase. - Do you think we should make it translateable? In my mind yes, but then I do see a lot of occurrences in Core — especially these older Admin pieces — of this ellipsis being hardcoded:
wp-includes/general-template.php :4783: $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
wp-admin/edit-comments.php :169: $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
wp-admin/themes.php :252: <?php echo ! empty( $_GET['search'] ) ? __( '…' ) : count( $themes ); ?></span>
wp-admin/nav-menus.php :650: wp_html_excerpt( $_nav_menu->name, 40, '…' );
… whereas I expected something like:
// translators: If your locale needs a different [bla bla…]
$more = _x( '…', 'ellipsis or equivalent typographic marker of a trimmed excerpt' );
// ...
wp_trim_words( $excerpt, 15, $more ) )There was a problem hiding this comment.
I like the space before the ellipsis, but I agree that it would be better to stay consistent with other excerpts (I applied the change).
Translating the string can be a separate discussion. If this ellipsis is translated, it probably should be used for comments and the nav menu name too, but that would not fit the same context as the translatable string found in the pagination or theme count placeholder.
| <?php | ||
| /* translators: %s: Post title. */ | ||
| printf( __( 'Select %s' ), _draft_or_post_title() ); | ||
| printf( __( 'Select %s' ), $post_title ); |
There was a problem hiding this comment.
I wonder if this might make it more confusing for users with screen readers or not. Visual users have the luxury of styling to differentiate "(no title)" (bold) from the trimmed excerpt (regular weight).
Should we rearrange the output for screen readers? Otherwise it'll look like this:
<span class="screen-reader-text">Select (no title) Lorem ipsum dolor sit amet</span>There was a problem hiding this comment.
The value of changing the font-weight is debatable.
However, I do not agree about rearranging the order of "(no title)" and the excerpt.
- I thought I had seen a similar discussion, either on Trac or Slack, about matching invisible label text to the visible text. The closest I found was Trac 63620, where both the invisible label and visible text are exactly the same. In the posts list table, the invisible label includes "Select", and most languages have that before the title.
- When the link's accessible name and visible text are "(no title) Lorem ipsum", the label can include the same text in the same order. Technique G211 mentions matching label text to adjacent visible text that "serves as its label". The link technically does not serve as the checkbox's label, but it can serve a similar purpose in addition to being a link on its own.
Ultimately, I do not think these new links and labels can be as accessible as having real, unique titles for every post.


If the post/page has no title and the excerpt is not already showing, this
Trac 65022
Use of AI Tools: none
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.