Make WordPress Core

Opened 2 weeks ago

Last modified 12 days ago

#65834 new enhancement

Tabs block: Extract Tab Panel content when generating automatic excerpts

Reported by: huzaifaalmesbah Owned by:
Priority: normal Milestone: Future Release
Component: Editor Version: 7.1
Severity: normal Keywords:
Cc: Focuses:

Description

The new Tabs block can contain meaningful content inside its Tab Panels. However, when WordPress automatically generates an excerpt for a post containing a Tabs block, the content inside the Tab Panels is not included in the generated excerpt.

The Tabs block has the following structure:

Tabs
├── Tab List
│   ├── Tab
│   └── Tab
└── Tab Panels
    ├── Tab Panel
    │   ├── Heading
    │   ├── Paragraph
    │   └── List
    └── Tab Panel
        └── ...

For example, the first Tab Panel may contain:

Welcome to WordPress 7.1

WordPress 7.1 introduces several improvements and new features.

• Feature 1
• Feature 2
• Feature 3

When the post does not have a manually defined excerpt, this content is currently not considered when generating the automatic excerpt.

Steps to reproduce

  1. Create a new post.
  2. Add a Tabs block.
  3. Add at least two tabs.
  4. In the first Tab Panel, add:
    • A Heading.
    • A Paragraph.
    • A List with a few items.
  5. Add different content to the second Tab Panel.
  6. Publish the post without adding a manual excerpt.
  7. Open the post through the REST API: yoursiteurl/wp-json/wp/v2/posts/<post-id>
  8. Check the excerpt.rendered value.

Actual result

The content inside the Tab Panel is not included in the automatically generated excerpt.

For example:

"excerpt": {
    "rendered": "",
    "protected": false
}

Expected result

The automatically generated excerpt should include meaningful text from the Tab Panel.

For example:

"excerpt": {
    "rendered": "<p>Welcome to WordPress 7.1 WordPress 7.1 introduces several improvements and new features. Feature 1 Feature 2 Feature 3</p>",
    "protected": false
}

Proposed solution

Consider extracting text content from the first Tab Panel when generating an automatic excerpt.

The first Tab Panel is the initially visible/default panel, so its content could be used as the primary source for the generated excerpt.

Nested text-based blocks such as Headings, Paragraphs, and Lists should be considered.

Using only the first Tab Panel would also avoid combining potentially unrelated content from multiple panels.

Testing

A test should cover a post containing:

  • A Tabs block.
  • Multiple tabs and Tab Panels.
  • A Heading, Paragraph, and List inside the first Tab Panel.
  • Different content inside a second Tab Panel.
  • No manually defined excerpt.

The test should verify that the generated excerpt contains the text from the first Tab Panel and does not unexpectedly include content from subsequent Tab Panels.

Change History (2)

#1 @wildworks
2 weeks ago

  • Milestone Awaiting ReviewFuture Release
  • Type defect (bug)enhancement

Thanks for the suggestion. This looks like a feature enhancement rather than a bug to me. Let's consider implementing it in a future release.

#2 @abcd95
12 days ago

excerpt_remove_blocks() has a hard-coded list of containers it recurses into, like columns, column, group. Tabs isn't there, so the whole block gets dropped, and the excerpt is empty.

I belive adding core/tabs to that wrapper list would recurse into all panels and tabs holding different content would all get mashed together in the excerpt, which is worse than empty.

The right approach I think is pulling from the first panel, but that has a real weakness: if the active panel only has a short heading, the excerpt is still nearly empty and it also ignores the activeTabIndex attribute, which lets editors set any tab as the default. If someone has deliberately made Tab 3 the visible default, pulling from Tab 1 doesn't reflect their intent at all. So ideally we must emit panels starting from activeTabIndex, then continue through the rest in document order. wp_trim_words() handles the 55-word cutoff as normal, so panels beyond the limit are never included and the excerpt stays coherent.

I also found that other blocks like core/details and core/accordion-item have the same gap, so probably we should open a tracking issue to fix all blocks.

Note: See TracTickets for help on using tickets.