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

Blocks: Related Posts block displayed wrong on Page templates #39720

Closed
alinclamba opened this issue Oct 10, 2024 · 2 comments · Fixed by #39730
Closed

Blocks: Related Posts block displayed wrong on Page templates #39720

alinclamba opened this issue Oct 10, 2024 · 2 comments · Fixed by #39730
Assignees
Labels
[Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] High [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack Triaged [Type] Bug When a feature is broken and / or not performing as intended

Comments

@alinclamba
Copy link

Impacted plugin

Jetpack

Quick summary

The Related Posts block is missing styles on Page templates after the latest Jetpack update. It still works as expected on Single post templates. On Pages, the Related Posts are displayed as a simple vertical list, while on Posts, they are correctly shown in a three-column layout, as intended.
This was reported by a user here: https://wordpress.org/support/topic/related-posts-block-on-page-template-broken-style-since-last-update/

Steps to reproduce

  1. Add a Related Posts block to both a Single post template and a Page template.
  2. Publish the templates and view them on the front end.
  3. Notice that the block is styled correctly in a three-column layout on Single posts, but displays as a simple list on Pages.

A clear and concise description of what you expected to happen.

No response

What actually happened

No response

Impact

Some (< 50%)

Available workarounds?

No but the platform is still usable

If the above answer is "Yes...", outline the workaround.

No response

Platform (Simple and/or Atomic)

No response

Logs or notes

No response

@alinclamba alinclamba added [Type] Bug When a feature is broken and / or not performing as intended Needs triage Ticket needs to be triaged labels Oct 10, 2024
@github-actions github-actions bot added [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack labels Oct 10, 2024
@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] High labels Oct 10, 2024
@anomiex
Copy link
Contributor

anomiex commented Oct 10, 2024

Looks like it accidentally worked before due to the style imploding, and broke when #39486 turned it off. cc @kraftbj @sergeymitr

The real problem is that the styles and scripts only get enqueued on posts, specifically

protected function enabled_for_request() {
$enabled = is_single()
&& ! is_attachment()
&& ! is_admin()
&& ! is_embed()
&& ( ! $this->allow_feature_toggle() || $this->get_option( 'enabled' ) );
/**
* Filter the Enabled value to allow related posts to be shown on pages as well.
*
* @module related-posts
*
* @since 3.3.0
*
* @param bool $enabled Should Related Posts be enabled on the current page.
*/
return apply_filters( 'jetpack_relatedposts_filter_enabled_for_request', $enabled );
}

while the block itself gets rendered regardless.

Something like this might work for a fix:

  • Change Jetpack_RelatedPosts::render_block() to return empty-string when that ::enabled_for_request() returns false, so the block doesn't render when the scripts aren't enqueued.
  • Expand the check in ::enabled_for_request() to allow pages and whatever else the block should work on.

Looks like the 'jetpack_relatedposts_filter_enabled_for_request' filter could be used as a workaround.

@kraftbj
Copy link
Contributor

kraftbj commented Oct 10, 2024

I'll put in a patch to allow it to be enqueued on pages as well. My understanding is the RP system will still kick out related posts on pages so let's continue to support that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] High [Status] Priority Review Triggered The guild in charge of triage has been notified of this issue in Slack Triaged [Type] Bug When a feature is broken and / or not performing as intended
Development

Successfully merging a pull request may close this issue.

4 participants