没有不值得去解决的问题,也没有不值得去学习的技术!

How to Fully Display Bilingual Post Excerpts in WordPress: Final Validation With WPCode and Gutenberg Post Excerpt

Figure 4: Full excerpt effect on the Chinese homepage

作者:

在

While maintaining my Chinese and English WordPress blog, I have always wanted the excerpts in the article lists to display as completely as possible.

The reason is simple: for the homepage, category pages, tag pages, and search result pages, excerpts are not just decoration. Readers usually judge whether an article is relevant to them based on the title and excerpt before deciding whether to enter the detail page. If the excerpt only shows a very short snippet, many articles will be truncated before they can even explain the background and core content, resulting in a poor reading experience.

This problem initially seemed very simple, but the actual troubleshooting process turned out to be much more complicated than I expected.

After a period of actual operation and further verification, I finally confirmed one thing:

Using WPCode to modify the excerptLength of the Gutenberg Post Excerpt block does indeed allow excerpts in both Chinese and English article lists to display almost completely.

And this has now been verified in practice on the Chinese homepage, Chinese category pages, and English search result pages.


1. The Initial Problem: Chinese Excerpts Were Particularly Prone to Being Too Short

The WordPress Gutenberg Post Excerpt block provides a “Max words” setting.

Initially, I used:

Plaintext
55

But in the actual frontend display, the Chinese excerpts were noticeably too short.

Later, I increased the excerpt length in the theme to:

Plaintext
100

This was already much better than before.

However, what I really wanted to achieve was not just “showing a little more than before”, but rather:

If an article already has a specifically written excerpt, display that excerpt as completely as possible.

This is especially true now that many article excerpts have been specifically generated and refined, serving as a complete article summary in themselves. If the list page only displays the first 100 characters, some information will still be lost.

Figure 1: Actual display effect when the theme excerpt limit is 100
Figure 1: Actual display effect when the theme excerpt limit is 100

As seen in the screenshot, the excerpt is already much longer than the initial 55, but it is still truncated in the middle and shows an ellipsis.

This indicates that:

Plaintext
100

is better suited as a fallback value rather than the final target.


2. Increasing the Post Excerpt Length to 500 via WPCode

My final solution was not complicated.

Continuing to use WPCode, I created a new PHP Snippet:

PHP
/**
 * SWQ:列表页 Post Excerpt 尽量完整显示文章摘要。
 */
add_filter(
    'render_block_data',
    function ( $parsed_block ) {

        if ( 'core/post-excerpt' === ( $parsed_block['blockName'] ?? '' ) ) {
            $parsed_block['attrs']['excerptLength'] = 500;
        }

        return $parsed_block;
    },
    20
);

The core logic does only one thing:

PHP
$parsed_block['attrs']['excerptLength'] = 500;

That is, before the Gutenberg core/post-excerpt block is actually rendered, the excerpt length limit is increased to 500.

For the Chinese and English article excerpts I normally generate now, 500 is already far greater than the actual length of the vast majority of excerpts, so the practical effect is basically equivalent to:

Displaying the existing excerpt in full.

This does not modify the excerpts in the database, nor does it regenerate excerpts; it simply relaxes the display length limit during frontend rendering.


3. Delegating Page Checks to WPCode Instead of Piling Up PHP Conditionals

Initially, I could have also checked the current page in PHP code using:

PHP
is_front_page()
is_home()
is_archive()
is_search()

to determine the current page.

However, since WPCode itself already provides Location and Smart Conditional Logic, I preferred to:

Let WPCode decide “where to run”, while the PHP code is only responsible for “what to do after running”.

This keeps the code itself much simpler.

Figure 2: WPCode using Frontend Conditional Logic
Figure 2: WPCode using Frontend Conditional Logic

The final settings are:

Plaintext
Insert Method:Auto Insert
Location:Frontend Conditional Logic

This leaves the page scope directly controlled by WPCode.

The PHP code no longer needs to include checks for page types like the homepage, archives, or search pages.


4. Smart Conditional Logic Retains Only Three Types of List Pages

Next, enable:

Plaintext
Enable Logic

Condition selection:

Plaintext
Show

Then create three independent condition groups:

Plaintext
Homepage
OR
Archive
OR
Search Page
Figure 3: Three condition groups for Homepage, Archive, and Search Page
Figure 3: Three condition groups for Homepage, Archive, and Search Page

The three condition groups are connected using OR.

This means that as long as the current page belongs to any one of them, the Snippet will run.

Homepage

Handles the homepage article list.

Archive

Handles various archive lists, such as:

Plaintext
Category pages
Tag pages
Date archives
Other taxonomy archives

Search Page

Handles internal search results.

I did not include Author Page.

Because my site has already disabled SEO display for author archives, there is no need to specifically maintain this type of list page.

The final responsibilities are thus very clear:

Plaintext
WPCode
│
├── Homepage
├── Archive
└── Search Page
        ↓
PHP Snippet
        ↓
core/post-excerpt
        ↓
excerptLength = 500

5. Why Did I Once Think This Code Was Ineffective?

This is actually the most interesting part of the whole process.

During early testing, I repeatedly toggled:

Plaintext
excerptLength = 500

And even deliberately tested:

Plaintext
excerptLength = 5

But the frontend page once appeared to have no changes at all.

So the troubleshooting scope gradually expanded to:

Plaintext
W3 Total Cache
Object cache
Page cache
CDN
WPCode execution status
Gutenberg block rendering
PHP code cache

Eventually, I even used a temporary MU Plugin specifically to verify the Gutenberg block rendering chain.

At that time, I could confirm:

Plaintext
attrs=5
early=6
late=6
final=6

This meant that excerptLength = 5 itself was actually effective.

5 characters plus an ellipsis resulted in a final length of exactly about 6.

This proved that:

render_block_data → core/post-excerpt → excerptLength

There was no problem with this technical approach itself.

What really complicated the judgment was the multi-layer caching in the production environment and the timing of code updates taking effect.


6. Unexpected Discovery Days Later: The Excerpts Had Actually Been Displaying Completely All Along

The real turning point came a few days later.

I noticed that the excerpts in the article lists on both the Chinese and English websites were actually already displaying almost completely.

I had originally assumed:

This was because the excerpt length in the theme had already been increased from 55 to 100.

Until I later accidentally discovered:

Plaintext
SWQ List pages display full article excerpts

This WPCode Snippet had actually been active the whole time.

So I manually deactivated it.

After a while, I observed the frontend again:

The excerpts reverted to about 100 characters, and obvious truncation reappeared.

This formed a very direct controlled experiment:

Plaintext
WPCode enabled
excerptLength = 500
↓
Excerpts display almost completely

Whereas:

Plaintext
WPCode disabled
↓
Reverts to theme settings
excerptLength = 100
↓
Excerpts truncated again

At this point, it was actually possible to confirm:

What truly caused the article lists to display excerpts in full was this WPCode snippet.

And the 100 in the theme was merely a fallback value for when the snippet was deactivated.


7. Reorganizing the WPCode Configuration and Continuing Observation

After confirming that the code was indeed effective, I re-enabled this Snippet and further organized the configuration into:

Plaintext
Location:
Frontend Conditional Logic

Enable Logic:
On

Conditions:
Homepage
OR Archive
OR Search Page

The code remains minimal:

PHP
/**
 * SWQ:列表页 Post Excerpt 尽量完整显示文章摘要。
 */
add_filter(
    'render_block_data',
    function ( $parsed_block ) {

        if ( 'core/post-excerpt' === ( $parsed_block['blockName'] ?? '' ) ) {
            $parsed_block['attrs']['excerptLength'] = 500;
        }

        return $parsed_block;
    },
    20
);

I then stopped immediately clearing the cache frequently and making repeated modifications, instead letting it run naturally in the real production environment for a while.


8. Final Verification 1: Chinese Homepage Excerpts Display Completely

Observing the Chinese homepage again, the excerpts in the list can be seen fully expanded.

Figure 4: Full excerpt effect on the Chinese homepage
Figure 4: Full excerpt effect on the Chinese homepage

For example, the excerpt for the first article on the homepage can now fully explain:

  • The Type-C to VGA issue with the ThinkPad T570;
  • Why I ultimately gave up on repairing the original link;
  • How the new monitor connects directly via HDMI;
  • The actual results after restoring the Ubuntu dual-screen setup;
  • The final verdict on Thunderbolt and DisplayPort Alt Mode.

If it were still the original 55 or 100 characters, this information would be difficult to fully convey in the article list.

Now, without entering the detail page, readers can already clearly judge:

What problem this article actually solves.

This is exactly the effect I originally hoped to achieve.


9. Final Verification 2: Chinese Category Pages Also Work

Next, I checked the Chinese category pages.

Figure 5: Chinese "Programming Languages" category page displaying full excerpts
Figure 5: Chinese “Programming Languages” category page displaying full excerpts

It can be seen that the article excerpts under the category:

Plaintext
Programming Languages

are also fully expanded.

For example:

Plaintext
A Tour of Go Chinese Translation Record: How to translate only the instructional code comments without breaking the Go code

The excerpt can fully introduce:

  • The translation page;
  • Protection of instructional code comments;
  • Protection of Go identifiers;
  • Automated validation;
  • Manual polishing;
  • Final verification results.

This also shows that:

Plaintext
Type of Page → Archive

has correctly covered the category archive pages.

There is no need to separately write PHP conditionals for:

Plaintext
Category
Tag
Taxonomy

.


10. Final Verification 3: English Search Results Also Display Completely

To confirm that this solution was not only effective for Chinese, I also checked the search results page on the English site.

Figure 6: English search results displaying full excerpts
Figure 6: English search results displaying full excerpts

After searching for:

Plaintext
cloudflare

, the English article excerpts can also be seen displaying almost completely.

For example:

Plaintext
WordPress Homepage Still Shows Old Content After Publishing?
Testing EdgeOne and Cloudflare With a 2-Hour Cache for Homepage and Sitemap

The excerpt below can now fully introduce:

  • W3 Total Cache;
  • EdgeOne;
  • Cloudflare;
  • Cache duration for the homepage and Sitemap;
  • Stale CDN cache issues;
  • The final caching strategy adjustments.

The second article about 96-hour cache optimization also fully displayed a longer English excerpt.

This means it has now been verified in practice:

Plaintext
Chinese homepage      ✓
Chinese category pages ✓
English search page   ✓

And these three types of pages exactly correspond to the currently configured:

Plaintext
Homepage
Archive
Search Page

Therefore, this configuration has formed a complete closed loop.


11. Why Is the Theme Value of 100 Retained?

Although WPCode now uses:

Plaintext
500

I did not revert the:

Plaintext
100

in the theme editor back to 55.

The reason is that this perfectly forms two layers of protection.

Under normal circumstances:

Plaintext
WPCode running normally
↓
500
↓
Existing excerpts display almost completely

If someday in the future, due to:

  • WPCode being temporarily deactivated;
  • A plugin upgrade;
  • The Snippet encountering an error;
  • The code being temporarily disabled during debugging;

Then the page will automatically fall back to:

Plaintext
Theme default 100

Instead of reverting to the originally very short:

Plaintext
55

So the current structure can be understood as:

Plaintext
First layer:
WPCode = 500
Responsible for normal full display

Second layer:
Theme = 100
Responsible for reasonable degradation in exceptional cases

This maintenance approach is actually more robust.


12. The Biggest Lesson This Time: Do Not Conclude Code Ineffectiveness Too Early in a Cached Environment

What impressed me the most during this process was not these few lines of PHP.

What is truly worth recording is:

In a WordPress production environment with multiple caching layers, “refreshing the page immediately after modifying code” does not necessarily prove whether the code has taken effect.

Especially since my site simultaneously has:

Plaintext
WordPress
W3 Total Cache
Object cache
Page cache
CDN
WPCode
PHP OPcache

When multiple layers of state overlap, it easily leads to:

Plaintext
Code modified
↓
Immediate refresh
↓
Page still shows old result
↓
Mistakenly assuming code is ineffective

Ultimately, the most convincing part this time was not complex diagnostics, but the simplest long-term comparison:

Plaintext
Enable WPCode
→ Excerpts complete

Disable WPCode
→ Reverts to 100

Re-enable
→ Complete again

Coupled with the actual result verification a few days later on:

Plaintext
Chinese homepage
Chinese category pages
English search page

, the causal relationship was finally confirmed.


13. Final Configuration

This excerpt display solution is now officially established as:

WordPress Theme

Plaintext
Post Excerpt Max words: 100

As a fallback value.

WPCode

Plaintext
Snippet:
SWQ List pages display full article excerpts

Code Type:
PHP Snippet

Insert Method:
Auto Insert

Location:
Frontend Conditional Logic

Enable Logic:
On

Conditions:
Show

Conditions:

Plaintext
Homepage
OR
Archive
OR
Search Page

Code:

PHP
/**
 * SWQ:列表页 Post Excerpt 尽量完整显示文章摘要。
 */
add_filter(
    'render_block_data',
    function ( $parsed_block ) {

        if ( 'core/post-excerpt' === ( $parsed_block['blockName'] ?? '' ) ) {
            $parsed_block['attrs']['excerptLength'] = 500;
        }

        return $parsed_block;
    },
    20
);

Summary

The final implementation of this requirement is actually very simple:

Using WPCode, increase excerptLength to 500 when rendering the Gutenberg Post Excerpt block on specified list pages.

What really took time was the verification process.

After confirming the final real-world operation results, currently:

Plaintext
Chinese homepage       Full display ✓
Chinese category pages Full display ✓
English search page    Full display ✓

This also proves that the original technical direction was correct.

I am now more inclined to understand the excerpts in article lists as:

A content preview before the article detail page, rather than a piece of decorative text under the title.

Since excerpts have been specifically prepared for articles, readers should be allowed to see the complete information as much as possible before deciding whether to enter the detail page.

At this point, this excerpt display issue, going from 55 to 100 and finally to 500, can officially be brought to a close.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系