WordPress 2025 Theme + Polylang: Fix a full record of the missing language directory for the calendar link

在英文页面(https://www.shuijingwanwq.com/en/)中,日历上每个日期点击后跳转的链接仍然是 https://www.shuijingwanwq.com/2026/06/08/ 的形式,而不是预期的 https://www.shuijingwanwq.com/en/2026/06/08/。

From Classical to Block: Theme Migration

From Hueman to Twenty Twenty-Five, Topic Switching with Multilingual Menu Configuration

(1) From Hueman to Twenty Twenty-Five, Topic Switching with Multilingual Menu Configuration

经过以上步骤,语言切换器最终在页面上的效果符合预期。(见图 9)

(2) In a WordPress 2025 topic, move the Polylang language switch to the full record in the upper right corner

页眉导航宽度异常问题:导航被内容宽度限制(图 4)

(3) WordPress Twenty Twenty-Five Global Width Layout Practical Notes: Widescreen Full-Scale + Large Screen Limited Wide Configuration Scheme

中文(中国)前台首页:66主内容文章+33标准化侧边栏,区块正常显示(对应图6)

(4) Practice|WordPress Twenty-Five Block Theme Text Blog Home Transform the Classic Two-Column Homepage

改造完成最终首页效果(图5)

(5) WordPress Twenty Twenty-Five Two-column homepage transformation: Text Blog Small picture list template complete practical record

图11:样式重写后下拉美观,但层级子分类在原生 Option 标签下以空格缩进表示

(6) Debugging record of the beautification and rendering mechanism of the drop-down menu of the category list

图3:应用修正后的 CSS,日历占据了应有的侧边栏宽度,有文章的日子用主题同色系进行了高亮,悬停时会变黑

(7) Fixed the issue of “getting dissatisfaction” in the sidebar: WordPress 2025 theme calendar style optimization

图5:English 下的页面显示第二个 Language Visibility 区块

(8) Add the multi-language “Personal Brand” block to the sidebar of the blog homepage

图4:调整后的分页效果

(9) Troubleshooting and Repair of One FSE Page Loss: From Pure Layout Template to Query Loop

在英文页面(https://www.shuijingwanwq.com/en/)中,日历上每个日期点击后跳转的链接仍然是 https://www.shuijingwanwq.com/2026/06/08/ 的形式,而不是预期的 https://www.shuijingwanwq.com/en/2026/06/08/。

(10) WordPress 2025 Theme + Polylang: Fix a full record of the missing language directory for the calendar link

图4:中文站点,下拉菜单样式美观,显示“选择年份”。

(11) Optimize WordPress 2025 Themeser: A complete remodeling record of multilingual navigation, social links and archive drop-down bars

图2:分类页单栏效果

(12) From single column to two columns: the practical record of the sidebar and list structure of the WordPress category page unified first page

套用上述代码后,标签云立刻有了质的飞跃:

(13) Say goodbye to uneven! Create a modern label cloud for 2025 themes only with CSS

搜索“alipay”的结果,每篇文章都带了一张大尺寸的特色图片,紧跟着就是完整的正文内容。我的文章里还有代码片段,全都被拉出来显示在列表里,页面无限拉长,排版也乱糟糟的。如图1

(14) Is the search result page too long? I did a “break away” for the WordPress 2025 theme

在英文页面 https://www.shuijingwanwq.com/en/ 中,22 号显示蓝色链接

(15) Compatibility restoration practice of WordPress calendar in Polylang multi-language environment

Network检查确认:如图3

(16) WordPress Theme Migration: Does Emoji Process Code Need to Keep?

图2 Site Wide Header

(17) WordPress Tab NoIndex Optimization: Practical Sharing from Theme Migration to Code Refactoring

最近,我在检查我的 WordPress 网站时,发现浏览器开发者工具的控制台里出现了几个令人不安的红色错误信息:

(18) WordPress Console Error Troubleshooting Transcript: From jQuery conflict to Baidu statistical warning

problem background

After switching from Hueman theme to WordPress official 2025 theme (Twenty Twenty-Five), the website needs to support both Chinese and English, and uses the Polylang plugin to achieve internationalization. After the switching is complete, I found a weird problem:Links to components such as label clouds, category lists, etc. can be properly brought /en/ Language directory, only the link of the calendar gadget is ‘fallen’.

in the English page (https://www.shuijingwanwq.com/en/), the link to the jump after each date on the calendar is still https://www.shuijingwanwq.com/2026/06/08/ form, not expected https://www.shuijingwanwq.com/en/2026/06/08/.

in the English page (https://www.shuijingwanwq.com/en/)中,日历上每个日期点击后跳转的链接仍然是https://www.shuijingwanwq.com/2026/06/08/form, not expectedhttps://www.shuijingwanwq.com/en/2026/06/08/。

This problem will cause the user to jump to the date archive page of the Chinese version (the default language) after clicking the date from the English version of the calendar, instead of the corresponding English date archive, which seriously affects the user experience of multilingual sites.

Problem root analysis

Why is only the calendar ‘lost’?

After investigation, it was found that the default calendar gadget of WordPress did not use standard, multi-language compatible ones when generating date links. home_url() function, but use get_day_link(),get_month_link() and other lower-level functions. When these functions generate links,Language directory prefixes added by plugins such as Polylang will not be actively considered(such as /en/).

Other components such as tag clouds and category lists work fine because they correctly use functions that recognize the current locale to generate links. So no matter how PolyLang is set, the calendar ‘stubbornly’ generates links without language code.

Polylang configuration confirmation

Before you start, make sure that the basic settings of Polylang are correct:

  1. permalink structure:Settings > Permalinks Selected ‘Custom Structure’https://www.shuijingwanwq.com/%year%/%monthnum%/%day%/%post_id%/
  2. URL Modify settings:Language > Settings > URL modification ‘Set the language according to the directory name in the fixed link’ is checked
  3. default language: Chinese (open) as the default language, not displayed in the URL /zh/ Directory

The debug code also verifies that the language recognition is normal:

  • Chinese homepage:<!--polylang current language: en -->
  • English homepage:<!--polylang current language: en -->

Since the Polylang settings are correct, the problem lies in the calendar gadget itself – the calendar link needs to be ‘manually’ corrected through code.

Solution: Add custom code using WPCode plugin

directly modify the subject functions.php Although the file is feasible, the modification will be lost when the theme is updated. more recommended wpcode Plugins to safely add custom code snippets.

Step 1: Install the WPCode plugin

In the WordPress background, enter plugin > install plugin, search wpcode, click ‘Install Now’ and activate it after finding it.

In the WordPress background, go to Plug-in > Install Plugin, search for WPCode, and click "Install Now" and activate it.

WPCode is a code management plugin that safely adds various code snippets (PHP, CSS, JavaScript, HTML, etc.) to WordPress without directly modifying the theme file.

Step 2: Go to Code Snippets and add new clips

After activating WPCode, go to the left menu Code Snippets(code snippet), click on the top add snippet(Add Fragment) button.

After activation of WPCode, go to Code Snippets (code snippet) in the left menu and click the Add Snippet button at the top.

In the page, find and click Add your custom code (new snippet) The card, the entrance to ‘Create Your Own’.

Step 3: Select the PHP Snippet type

After clicking, it will pop up create custom snippet window. In this window, you will see multiple code type cards, such as HTML Snippet, Text Snippet, CSS Snippet, JavaScript Snippet, PHP Snippet, Universal Snippet et al.

Click directly php snippet card, select the PHP code snippet type.

Click directly on the PHP Snippet card and select the PHP code snippet type.

Step 4: Paste the repair code and set it up

In the editing interface, fill in Title(such as ‘Fix multilingual calendar link’), and then paste the following fix code completely into Code preview in the code box:

PHP
<?php
/**
 * 为 WordPress 默认日历小工具的所有日期链接添加 Polylang 语言前缀
 * 仅在英文(en)页面生效,中文页面保持原样
 */
function fix_calendar_links_with_polylang( $calendar_output ) {

    // 1. 检查 Polylang 函数是否存在,且不在后台
    if ( function_exists( 'pll_current_language' ) && ! is_admin() ) {

        // 2. 获取当前语言
        $current_lang = pll_current_language();

        // 3. 只在英文页面进行替换
        if ( $current_lang === 'en' ) {

            // 4. 获取不带语言前缀的主页 URL(用于匹配旧链接)
            $home_url = home_url( '/' );

            // 5. 构建包含 /en/ 的正确主页 URL
            $correct_home_url = str_replace( 'https://www.shuijingwanwq.com/', 'https://www.shuijingwanwq.com/en/', $home_url );

            // 6. 在日历HTML中,将所有旧链接替换为新的
            $calendar_output = str_replace( $home_url, $correct_home_url, $calendar_output );
        }
    }

    return $calendar_output;
}
add_filter( 'get_calendar', 'fix_calendar_links_with_polylang' );

Code description:

  • 3rd line if ( $current_lang ===en) EnsureReplacement operations are only performed on English pages, the Chinese page is not affected
  • Line 5 build contains /en/ correct link
  • Line 6 performs link replacement

Insert position settings:
at the bottom of the editing interface Insertion area:

  • Insert method: select auto insert(auto insert)
  • location: select frontend only(Front-end only), make sure that the code is only effective at the front desk of the website, more secure
Insert position settings:

After completing the setting, set the switch in the upper right corner from inactive switch to active(Activate), click save snippet(Save the fragment).

Step 5: Clear the cache

After the code takes effect,Be sure to clear all caches:

  • WPCode does not require additional operations, the code saving takes effect
  • W3 Total Cache: Enter the plugin settings, click ‘Clear all caches’
  • Browser cache: press Ctrl + Shift + R(Windows/Linux) or CMD + SHIFT + R(MAC) Forced refresh
  • If using a CDN (such as Cloudflare), also clear the CDN cache

final verification result

After the repair is completed, visit the Chinese homepage and English homepage respectively to verify the calendar link:

PageBefore repairAfter repair
Chinese Home (/ / *)https://.../2026/06/16/https://.../2026/06/16/
English Home (/en/)https://.../2026/06/16/https://.../en/2026/06/16/
After the repair is completed, visit the Chinese homepage and English homepage respectively to verify the calendar link:

Stepping on the pit record and key points

Step on the pit 1: The first version of the code causes /en/en/ Repeat

When the original version of the code was replaced, it did not determine whether the current page already contained the language directory, resulting in the link being incorrectly removed from the English page. https://.../en/2026/... replace again with https://.../en/en/2026/....

Solution: In the replacement logic, only for links that do not contain language prefixes are processed.

Step on the pit 2: Chinese page was added by mistake /en/

Due to Chinese (open) as the default language, the URL does not contain /zh/ Directory, and the previous code is not limited to only take effect on the English page, resulting in the calendar link of the Chinese page being added incorrectly /en/.

Solution: increase if ( $current_lang ===en) judge,Only perform replacement operations on the English page.

Key points summary

  1. WordPress Default Calendar WidgetThe language directory of Polylang is not compatible with polylang when generating links, and needs to be passed through get_calendar Filters manually corrected
  2. Use the WPCode pluginAdd code to modify directly functions.php Safer and easier to manage
  3. Be sure to judge the current language, only perform replacements for languages (such as English) that need to be corrected to avoid affecting the default language page
  4. Remember to clear all caches after code modification, including plugin cache, browser cache and CDN cache

reference material

Troubleshooting and Repair of One FSE Page Loss: From Pure Layout Template to Query Loop Optimize WordPress 2025 Themeser: A complete remodeling record of multilingual navigation, social links and archive drop-down bars

评论

One response to “WordPress 2025 Theme + Polylang: Fix a full record of the missing language directory for the calendar link”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.