After migrating the English WordPress site from www.shuijingwanwq.com/en/ to a separate subdomain en.shuijingwanwq.com, the English article pages and homepage were accessible. However, upon further inspecting the homepage and category archive pages, I found that links generated by some blocks still pointed to the Chinese main domain or the old /en/ path.
The most obvious issue was the category dropdown list on the English homepage. After selecting the Browser category, the browser did not navigate to the English category page, but instead to:
https://www.shuijingwanwq.com/?category_name=browser-en
Ultimately, a 404 is returned.
Further investigation revealed that this was not an isolated link, but rather an issue affecting category dropdowns, the site title, footer menu, English navigation, breadcrumbs, and permalinks across different templates.
This article documents the entire process of inspection, fixing, and verification.
1. Current Multi-Domain Structure
The site uses WordPress, Polylang, Twenty Twenty-Five, and W3 Total Cache.
The current language-to-domain mapping is as follows:
中文站:
https://www.shuijingwanwq.com/
英文站:
https://en.shuijingwanwq.com/
The English site was previously located at:
https://www.shuijingwanwq.com/en/
After completing the subdomain migration, Nginx still retains the 301 compatibility rules for the old /en/ path. As a result, some legacy links still work but incur an extra redirect.
Previously, we also investigated an issue where English calendar links were concatenated into a double URL:
https://www.shuijingwanwq.com/2026/07/11/19354/
The issue discovered this time is similar to the calendar problem: the block content has been identified as English, but some dynamic links still use the WordPress default Chinese site homepage URL.
II. Initial Discovery: English Category Dropdown Returns 404
After selecting Browser from the category dropdown on the English homepage, the browser redirects to:
https://www.shuijingwanwq.com/?category_name=browser-en
The response status is:
404
However, the correct query URL for the English category should be:
https://en.shuijingwanwq.com/?category_name=browser-en
It will then redirect to the actual taxonomy archive:
https://en.shuijingwanwq.com/category/application-tool-en/browser-en/
and returns a 200 status code normally.
This indicates that:
- The English category slug
browser-enis correct; - The category data itself is not lost;
- The permalink rules are not broken;
- The actual error is that the category dropdown uses the Chinese primary domain.
3. Checking the Category Dropdown Block
In the theme editor, locate the “Category List” block. You will see that it uses the WordPress categories and has “Display as dropdown” enabled.

This block allows you to configure:
- Whether to display as a dropdown menu;
- Whether to display the post count;
- Whether to display only top-level terms;
- Whether to display empty terms;
- Whether to display the hierarchy.
However, there is no option to set a redirect domain.
The category options output on the English page are correct:
<option value="browser-en">Browser (32)</option>
The issue lies in the auto-generated dropdown navigation script in WordPress:
[
"wp-block-categories-1",
"https://www.shuijingwanwq.com"
]
When the user selects Browser, the script appends the category slug to the Chinese homepage:
https://www.shuijingwanwq.com/?category_name=browser-en
The English homepage outputs a total of 742 category options, of which 735 category slugs end with -en. Therefore, this is not a single category error; rather, the entire English category dropdown list contains domain errors.
4. Why Not Globally Modify home_url()
One seemingly straightforward solution would be to globally modify WordPress’s home_url() to the English domain when the request comes from en.shuijingwanwq.com.
This approach might fix some dynamic links, but it cannot fix all issues.
Links within the site fall into two main categories.
1. Dynamically Generated Links
For example:
- Category dropdown;
- Site title;
- Breadcrumb Home;
- Some search, archive, and block links.
These links might call home_url() or similar functions during rendering.
2. Hardcoded Links Saved in Blocks or Navigation
For example:
https://www.shuijingwanwq.com/en/
Or:
/en
These links are already hardcoded into navigation blocks, paragraphs, or template content. Globally modifying home_url() will not automatically rewrite them.
Additionally, globally filtering home_url() may also affect:
- REST API;
- Login and logout redirects;
- AJAX requests;
- Form submissions;
- Admin preview;
- Plugin callback URLs;
- Polylang domain detection;
- W3 Total Cache cache keys.
Therefore, the final approach adopted was “dynamic link targeted fixing + sequential permalink modification.”
V. First Attempt: Using render_block_core/categories
The initial attempt was to filter the Categories block output via render_block_core/categories to replace the Chinese homepage with the current language’s homepage.
However, inspecting the dynamic response from the source site revealed that the category redirect script automatically generated by WordPress was not present in the block HTML that the filter could modify.
The relevant JavaScript was only appended to the page after the filter had finished executing.
As a result, the page still output:
[
"wp-block-categories-1",
"https://www.shuijingwanwq.com"
]
This attempt did not work.
6. Second Attempt: Using PHP Output Buffering to Replace the Final HTML
Next, I tried starting output buffering during the template_redirect hook to perform a regex replacement on the category scripts within the final HTML.
However, under the current W3 Total Cache output buffering environment, the replacement still did not appear in the final response.
Even when using:
- Cloudflare MISS requests;
- Requests with unique query parameters;
- Dynamic POST requests;
The final HTML still retains the original Chinese domain.
This indicates that under the current combination of caching and output buffering, directly rewriting the full HTML is not stable enough.
7. Final Solution: Intercepting the Category Dropdown Event on the Frontend
Ultimately, instead of continuing to modify the original WordPress scripts, we prioritized intercepting the change event when the category dropdown changes.
Create a new WPCode PHP snippet:
修复非默认语言站分类下拉列表跳转域名
The final code is as follows:
add_action(
'wp_footer',
function () {
?>
<script id="swq-fix-category-dropdown-domain">
document.addEventListener('DOMContentLoaded', function () {
document
.querySelectorAll(
'select[name="category_name"][id^="wp-block-categories-"]'
)
.forEach(function (dropdown) {
dropdown.addEventListener(
'change',
function (event) {
if (
!dropdown.value ||
dropdown.value === '-1'
) {
return;
}
event.stopImmediatePropagation();
const url = new URL(
window.location.origin
);
url.searchParams.set(
dropdown.name,
dropdown.value
);
window.location.href = url.href;
},
true
);
});
});
</script>
<?php
},
100
);
WPCode is set to:
Code Type:PHP Snippet
Insert Method:Auto Insert
Location:Run Everywhere
Status:Active
Although Location uses Run Everywhere, the code hooks into:
wp_footer
It only outputs the patch on the front-end pages where wp_footer() is called, and does not output it in the WordPress admin area via admin_footer.
Instead of hardcoding an English domain name, this code uses:
window.location.origin
Therefore:
- The Chinese site automatically uses
https://www.shuijingwanwq.com; - The English site automatically uses
https://en.shuijingwanwq.com; - Additional language domains added in the future can also be automatically adapted.
8. WPCode is Enabled, but Code is Not Loading on English Domains
After enabling the snippet, the inspection results initially showed:
www.shuijingwanwq.com:补丁正常输出
en.shuijingwanwq.com:补丁没有输出
This indicates that the code itself has no syntax issues and the WPCode snippet is active, but the English domain is still reading the stale object cache.
This is consistent with the W3 Total Cache Object Cache issue previously seen in the Polylang multi-domain environment.
Use the host-based object cache clearing script prepared earlier:
/root/bin/w3tc-flush-host-object-cache \
en.shuijingwanwq.com
Execution result:
已按以下 Host 启动 WordPress,并调用 W3TC Object Cache 清理:
en.shuijingwanwq.com
After flushing the English Host object cache, the English origin finally output:
<script id="swq-fix-category-dropdown-domain">
The actual browser test results are:
选择 Browser
→ https://en.shuijingwanwq.com/category/application-tool-en/browser-en/
→ 200
The category dropdown issue has been successfully fixed.
9. Continuing to Check Other Links on the English Homepage
After fixing the category dropdown, I proceeded to check all standard links and dynamic controls on the English homepage.
The inspection scope includes:
- Standard
<a>links; - Category dropdown list;
- Archives dropdown list;
- Header navigation;
- Footer navigation;
- Site title;
- Calendar;
- Pagination;
- Search form;
- Chinese-English language switcher.
Several more legacy links were subsequently discovered.
10. Fixing the Blog Link in the Footer
The original Blog link in the English footer was:
https://en.shuijingwanwq.com/en
Instead of loading the English homepage, this URL was recognized by WordPress as a content slug, ultimately redirecting to a 2019 article:
https://en.shuijingwanwq.com/2019/07/17/15210/
As seen in the footer template component, the Chinese and English menus are controlled by two separate Language Visibility blocks.
![[Figure 2: Chinese and English Language Visibility menus in the footer template]](https://media.shuijingwanwq.com/2026/07/2-36-1024x485.png)
The English Blog uses a custom link:
/en
Change it to:
/
![[Figure 3: Changing the English footer Blog link from /en to /]](https://media.shuijingwanwq.com/2026/07/3-35-1024x485.png)
After saving the template and flushing the English Host object cache, the English origin server output becomes:
<a href="/" target="_blank">
<span>Blog</span>
</a>
It will redirect directly to the homepage of the current English domain.
11. Fixing the Header and Footer Site Titles
Both the header and footer Yongye site titles on the English pages originally pointed to:
https://www.shuijingwanwq.com/
Clicking it will take you to the Chinese homepage.
In the theme editor, check the “Site Title” block; on the right side, there is only:
- Link the title to the homepage;
- Open in a new window.
There is no option to manually set the homepage URL.
![[Figure 4: The Site Title block only allows you to set whether it links to the homepage]](https://media.shuijingwanwq.com/2026/07/4-35-1024x485.png)
Therefore, I created a new WPCode snippet to fix the homepage link for multiple domains.
Later, the breadcrumbs Home link encountered the same issue, so the snippet name was ultimately changed to:
修复多域名动态首页链接
The final code is as follows:
add_action(
'wp_footer',
function () {
?>
<script id="swq-fix-multidomain-home-links">
document.addEventListener('DOMContentLoaded', function () {
document
.querySelectorAll(
[
'.wp-block-site-title a',
'.wp-block-breadcrumbs ol > li:first-child a'
].join(',')
)
.forEach(function (link) {
link.href = window.location.origin + '/';
});
});
</script>
<?php
},
100
);
WPCode is set to:
Code Type:PHP Snippet
Insert Method:Auto Insert
Location:Run Everywhere
Status:Active
It updates the site title and breadcrumb homepage link to point to the homepage of the current page’s domain.
English page verification results:
顶部 Yongye
→ https://en.shuijingwanwq.com/
底部 Yongye
→ https://en.shuijingwanwq.com/
12. Fixing the “Home” Menu in the Top Navigation
The “Home” link in the top navigation was originally linked to the old English homepage:
https://www.shuijingwanwq.com/en/
![[Figure 5: The English main menu Home still links to the old /en page]](https://media.shuijingwanwq.com/2026/07/5-29-1024x422.png)
Although Nginx can 301 redirect it to the English subdomain, this introduces an unnecessary redirect.
In the English main menu, change Home to a custom relative link:
/
![[Figure 6: English Home menu modified to relative path /]](https://media.shuijingwanwq.com/2026/07/6-25-1024x422.png)
After saving and flushing the English Host object cache, the origin output becomes:
<a href="/">Home</a>
13. Fixing the About Me & Contact on the Blog Homepage
The original links in the personal branding section of the English blog homepage were:
https://www.shuijingwanwq.com/en/about-me-contact-2/
This content is located within the English-specific Language Visibility block, so it can be modified independently without affecting the Chinese links.
![[Figure 7: Old About Me & Contact links in the English Language Visibility]](https://media.shuijingwanwq.com/2026/07/7-16-1024x444.png)
Change it to:
/about-me-contact-2/
After saving and flushing the English Host object cache, the English origin outputs:
<a href="/about-me-contact-2/">
👉 About Me & Contact
</a>
14. Checking the English Category Archive Page
After fixing the English homepage, proceed to check:
https://en.shuijingwanwq.com/category/programming-language-en/
Basic check results:
HTTP:200
lang:en-US
canonical:https://en.shuijingwanwq.com/category/programming-language-en/
页面标题:Programming Language Category Archives - Yongye
H1:Category: Programming Language
The pagination links also correctly use the English domain:
https://en.shuijingwanwq.com/category/programming-language-en/page/2/
After actually selecting Browser from the category dropdown, you can also proceed:
https://en.shuijingwanwq.com/category/application-tool-en/browser-en/
15. Two Separate Issues Found on the Category Pages
Although the English homepage is now working correctly, the category archives use the “All Archives” template, which means two legacy links still remain:
- The breadcrumb “Home” points to the Chinese homepage;
- The About Me & Contact section in the category template sidebar still points to the old
/en/URL.
This indicates that different templates in a WordPress block theme may contain block content that appears identical but is actually independent of one another.
Modifying the blog homepage template will not automatically modify all archive templates.
16. Fixing the Breadcrumb Home
The breadcrumb block in the theme editor can only be configured to:
- Whether to display the homepage breadcrumb;
- Whether to display the current page;
- Separator.
![[Figure 8, Breadcrumb settings in all archive templates]](https://media.shuijingwanwq.com/2026/07/8-14-1024x314.png)
It does not have a homepage URL setting.
The frontend structure is:
<nav class="wp-block-breadcrumbs">
<ol>
<li>
<a href="https://www.shuijingwanwq.com/">
Home
</a>
</li>
</ol>
</nav>
Therefore, add .wp-block-breadcrumbs to the previous “Fix Dynamic Homepage Links for Multiple Domains” code snippet.
After the fix:
面包屑 Home
→ https://en.shuijingwanwq.com/
17. Fix the About Link in All Archive Templates
In the “All Archives” template, locate About Me & Contact under the English Language Visibility, and change:
https://www.shuijingwanwq.com/en/about-me-contact-2/
Change to:
/about-me-contact-2/
Save the template and flush the English Host object cache again.
18. Final Verification Results
Perform a final review of the English homepage and English category archive pages.
English category page:
https://en.shuijingwanwq.com/category/programming-language-en/
The final result is as follows:
HTTP 状态:200
页面语言:en-US
canonical:正确
H1:Category: Programming Language
面包屑 Home:英文首页
顶部 Yongye:英文首页
底部 Yongye:英文首页
Header Home:英文首页
Footer Blog:英文首页
About Me & Contact:英文页面
分类下拉列表:正常
分类分页:正常
Broken link statistics:
错误指向 www 中文域名:0
旧 www/en/ 路径:0
en.shuijingwanwq.com/en:0
The only link on the page that still points to www.shuijingwanwq.com is:
中文(中国)
This is the normal language switcher link.
19. Cloudflare Cache Handling Strategy
During the fix, old pages already cached in Cloudflare will not immediately include the new code.
Since the category dropdown, site title, and sidebar exist across a large number of pages, purging URLs one by one would be highly labor-intensive.
The strategy ultimately adopted is:
- Verify that the dynamic responses from the English origin site are functioning normally;
- Validate the new output using POST requests, unique query parameters, or cache MISS requests;
- Do not purge the entire Cloudflare cache;
- Allow existing page caches to expire naturally;
- Newly generated or expired pages will automatically include the patch.
Therefore, during the transition period, a small number of cached pages may temporarily still display old links, but this will not affect the final state of the origin server.
20. Lessons Learned from This Troubleshooting
1. Completing a Multi-Domain Migration Does Not Mean All Template Links Have Been Migrated
Even if Polylang, Nginx, canonical tags, and post links are all functioning correctly, block templates may still retain:
- Old absolute URL;
- Old
/en/path; - Default language
home_url(); - Old page links in the navigation.
2. Dynamic Links and Permalinks Require Separate Handling
Dynamic links are suitable for fixing via small code patches.
Permalinks should be modified directly in the corresponding template or navigation block.
3. Different Templates in Block Themes Have Independent Content
The blog homepage template, all archive templates, the header template part, and the footer template part may each store their own block content separately.
Modifying an About link in one template does not mean that similar links in other templates will update automatically.
4. After Updating WPCode, Monitor the Object Cache
In the current W3 Total Cache multi-domain environment, a successful WPCode save does not mean that other hosts will immediately read the latest code snippet.
If the following occurs:
www 域名已经加载
en 域名没有加载
You should first check the Object Cache on the current Host rather than continuing to modify the code.
5. Do Not Rely Solely on Whether the Page Loads
Old links might continue to work via 301 redirects, but they still introduce:
- Unnecessary redirects;
- Incorrect language switching;
- Increased caching complexity;
- Inconsistent search engine crawling paths;
- Difficulty in maintaining subsequent rules.
The final review should focus on both:
- Original
href; - HTTP status code;
- Final URL;
- Number of redirects;
- Page language;
- canonical;
- Actual browser interactions.
21. Conclusion
The issue initially appeared as the English category dropdown returning a 404, but a thorough investigation revealed that it involved multiple layers:
Polylang 语言域名
WordPress 区块动态脚本
区块主题模板
Language Visibility
导航固定链接
面包屑首页链接
WPCode
W3 Total Cache Object Cache
Cloudflare 页面缓存
The final approach adopted is:
- Fix the category dropdown using a frontend event patch;
- Fix the site title and breadcrumb Home using the current domain;
- Change Home and Blog to
/in the English menu; - Change the English About link to a relative path;
- Check the blog homepage and all archive templates respectively;
- Flush the W3 Total Cache Object Cache per Host;
- Let the old Cloudflare cache expire naturally.
The final English homepage and English category archive pages no longer contain incorrect Chinese domain names or legacy /en/ links. The category dropdown, pagination, breadcrumbs, and navigation are all functioning normally.
需要长期技术维护或远程问题排查?
我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。
如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:
- ✅ PHP / Laravel / Yii2 老项目无人维护
- ✅ Go / Gin 后端接口需要排查或优化
- ✅ WordPress 网站访问慢、报错或插件冲突
- ✅ Nginx / MySQL / Redis / Linux 服务器异常
- ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
- ✅ 需要长期远程技术支持或兼职维护
更多介绍请查看:关于我 & 合作
微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan


发表回复