Gutenberg: [ Latest Posts ] The "Continue reading" link added to excerpts by some default themes has the wrong URL

Created on 27 Feb 2020  路  8Comments  路  Source: WordPress/gutenberg

Describe the bug
Some default themes (Twenty Thirteen through Twenty Seventeen) use the excerpt_more filter to add a "Continue Reading" link at the end of trimmed excerpts. They all use basically the same function, which looks like this:

$link = sprintf(
    '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
    esc_url( get_permalink( get_the_ID() ) ),
    /* translators: %s: Name of current post */
    sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
);

When this filter is applied to excerpts in the context of the Latest Posts block, however, the context of the global $post object is not what the theme function expects, so get_the_ID() is picking up the ID of the post or page where the Latest Posts block is located, rather than the post that is being rendered within the block. Thus, the links appended to excerpts within the block are not linking to the right place.

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. The "Continue Reading" links do not link to the actual posts. (The other problem, of there being two links at the end of the excerpt, is described in #20510)

Expected behavior
Perhaps if the render_block_core_latest_posts() function used setup_post_data() within its loop for rendering each post item, the links would contain the correct URLs. But I haven't tested this.

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Browser: Firefox 73
  • WP: 5.3.2
  • Gutenberg: 7.6.0
[Block] Latest Posts [Status] In Progress [Type] Bug [Type] Regression

All 8 comments

I can confirm this and was about to report it myself. ;)

It may be worth noting that this is a regression in that this does not occur when you disable the Gutenberg plugin and rely on the Gutenberg build that is included in WordPress 5.3.2.

In my testing, not only the link is wrong but with Twenty Sixteen and master Gutenberg I see two links, a read more from LatestPosts and a continue reading from the theme. This is caused that now LatestPosts is using get_the_excerpt instead of trimming content and the read more it adds does not respect the excerpt more filter.

Fixing this in the PR referenced above raises another issue: the "read more" displayed by the edit mode of the LatestPosts block is not "connected" to the one set by the theme at render time. E.g.

  • With Twenty Sixteen I see "Read more" in the editor
  • On the front end I see "Continue reading"

Feels like a minor problem, but I do wonder if there is a way to know what that label is in Gutenberg, and also if this is a show stopper now.

Encountered this with the Alves theme on the default homepage template. When applying a list of posts using the Latest post block it has the "Continue Reading" link at the end of the post excerpt which links to the homepage, and not the link of the post.

There is a PR fixing this #20541 but it needs a review/approval.

Edit: uh, sorry, this was meant for https://github.com/WordPress/gutenberg/issues/20510. Reposted there.

Which version of Wordpress will this fix be implemented in? I have the latest (5.4.2) and it's not there.

It appears that this will be included in the gutenberg that is included in the upcoming version of wordpress 5.5 that scheduled for august. If you would like to have the fix now, I believe it's also available in the gutenberg plugin itself; which you could download and activate in wordpress.org/plugins/gutenberg

Was this page helpful?
0 / 5 - 0 ratings