Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Latest Posts ] Appending "Read More" to the excerpt is inconsistent with some default themes #20510

Closed
coreymckrill opened this issue Feb 27, 2020 · 8 comments
Labels
[Block] Latest Posts Affects the Latest Posts Block [Type] Bug An existing feature does not function as intended

Comments

@coreymckrill
Copy link
Contributor

Describe the bug
When the excerpt is enabled in Post content settings, the block attempts to check if the default … that is appended to trimmed excerpts has been modified. If not, it appends a "Read More" link to the end of the excerpt. The problem is, the substring that it's looking for is not accurate for determining if modification has already happened. This causes unintended behavior in some default themes:

  • Twenty Sixteen, Twenty Seventeen, and perhaps some others, modify excerpt_more with their own "Continue Reading" link, but still use … as well, so this causes there to be two separate, redundant links at the end of each excerpt.
  • Twenty Nineteen and Twenty Twenty don't modify the default excerpt_more at all, but this also isn't detected correctly by Latest Posts, because the default string is '[…]', while Latest Posts is looking for ' … ' (note the spaces). So in these themes, the excerpts don't get any "Read More" link at all, though it seems like the intention is that they should.

To reproduce

  1. Publish a couple of posts with a significant amount of content (so it will get trimmed for the excerpt).
  2. Add the Latest Posts block to a page. In Post content settings, turn on Post content, and then ensure that the Excerpt is the type of content to show.
  3. With Twenty Sixteen activated, view the page. It will show something like … Continue readingRead more at the end of each post. Note that this isn't what is shown in the block preview.
  4. With Twenty Twenty activated, view the page. Each post excerpt will have [...] at the end, but no "Read More" link. Note that this isn't what is shown in the block preview.

Expected behavior
Ideally, I think, the Latest Posts block would make a has_filter check on excerpt_more and skip appending anything if that returns true, rather than checking for an arbitrary string.

Screenshots

Twenty Sixteen frontend:
2016_frontend

Twenty Sixteen editor:
2016_editor

Twenty Twenty frontend:
2020_frontend

Twenty Twenty editor:
2020_editor

Desktop

  • OS: macOS Catalina
  • Browser: Firefox 73
  • WP: 5.3.2
  • Gutenberg: 7.6.0
@skorasaurus
Copy link
Member

skorasaurus commented Feb 28, 2020

I'm also encountering this in our custom theme and would like advise on what I should expect to be used; I too expected that excerpt_more since we customize that text.

Using the 'the_content_more_link hook would also enable a developer to customize the by adding link classes.

This behavior is present in Gutenberg 7.6.0 as well as deactivating the gutenberg plugin and relying on Gutenberg that is built into
WordPress 5.3.2.

@draganescu
Copy link
Contributor

Related to #20511, in #20541 I removed the appending of read more by the LatestPosts block. That link should be there only if added by the result of running get_the_excerpt.

What do you think of this solution?

Also, an important question: how could the block be aware of what the theme does to that "read more" text?

@draganescu draganescu changed the title Latest Posts: Appending "Read More" to the excerpt is inconsistent with some default themes [ Latest Posts ] Appending "Read More" to the excerpt is inconsistent with some default themes Mar 1, 2020
@coreymckrill
Copy link
Contributor Author

What do you think of this solution?

I think that's a good idea, for the appending to only happen within the filter.

how could the block be aware of what the theme does to that "read more" text?

I don't think there's a perfect solution to this, but what I mentioned above in the ticket might get pretty close: use has_filter( 'excerpt_more' ) to see if anything at all is hooked to it. If so, it seems like a fairly safe assumption that we shouldn't append a link.

@talldan talldan added [Block] Latest Posts Affects the Latest Posts Block [Type] Bug An existing feature does not function as intended labels Mar 3, 2020
@skorasaurus
Copy link
Member

skorasaurus commented Mar 3, 2020

I think your PR is on the right path; we shouldn't automatically detect whether 'read more' is contained in the latest posts block.

EDIT:
The function that appended links to excerpts that Corey links to, is accessible for assistive technology users as it includes the context for the link by appending the title of the page to the link. (for example with a post titled "my summer vacation" the link would be "continue reading my summer vacation")

Additionally by hard coding the 'read more' in the latest posts block, theme developers aren't able to either modify that without extensive hacking of using regular expressions to search and replace the 'read more' text. (I would highly discourage hard coding 'read more' into the latest posts block).

Modifying the text at the end of an automatically generated excerpt has been possible through the excerpt_more hook
and in instances where the excerpt is a custom excerpt (represented by post->post_excerpt) and is excerpt_more is not called in those instances, you can use the get_the_excerpt filter.

(For context, twentytwenty only modifies excerpts when it's a more tag (<!--more--> ; which is modified through the the_content_more_link hook.

@azaozz
Copy link
Contributor

azaozz commented Mar 30, 2020

#20541 looks good for fixing this edge case, and partially fixes this issue.

When the option to display "Post content" is turned on it seems to mix two different WP features: post excerpts and the <!--more--> tag. It's true that the same mixing can also happen in themes, but there it can be handled better.

Thinking it's worth it revisiting/improving how the "Post content" option is handled. Seems better to use a consistent, auto-generated, text only excerpts that will also respect the length set by the user.

@akmyta
Copy link

akmyta commented Jun 4, 2020

A report was made about this here: #3034519-zen
I was able to replicate this issue on my own (launched) atomic site with the default theme Twenty Twenty and Gutenberg version 8.2.1

@jorgefilipecosta
Copy link
Member

Given that #20541 was merged, could we close this issue? @draganescu

@draganescu
Copy link
Contributor

I think so yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latest Posts Affects the Latest Posts Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants