最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

routing - How to change all routes with language codes

programmeradmin2浏览0评论

I need to dublicate all existing routes with several language codes:

/2020/03/11/Hello-world
/en/2020/03/11/Hello-world
/de/2020/03/11/Hello-world

/Hello-world-page
/en/Hello-world-page
/de/Hello-world-page

/...
/en/...
/de/...

Then I need to pre-handle all routes to check prefix exists and get as slug, then let related handlers do thier jobs.. I searched it many many times but never lucky to solve..

How to accomplish that? Thank you!

I need to dublicate all existing routes with several language codes:

/2020/03/11/Hello-world
/en/2020/03/11/Hello-world
/de/2020/03/11/Hello-world

/Hello-world-page
/en/Hello-world-page
/de/Hello-world-page

/...
/en/...
/de/...

Then I need to pre-handle all routes to check prefix exists and get as slug, then let related handlers do thier jobs.. I searched it many many times but never lucky to solve..

How to accomplish that? Thank you!

Share Improve this question edited Mar 11, 2020 at 18:31 Digerkam asked Mar 11, 2020 at 12:09 DigerkamDigerkam 2192 silver badges10 bronze badges 3
  • 1 Note that doing this would result in duplicated content which carries an SEO penalty. By default WP will redirect to the canonical page, and put the canonical URL in a meta tag to try and avoid this. Why would you want to duplicate all the URLs? – Tom J Nowell Commented Mar 11, 2020 at 12:42
  • @TomJNowell Well, for language and localization codes.. /en/us/Hello-world for example.. Maybe no need to do it with routing, it would be great that get route before wp proccess, seperate codes, then let wp does it jobs. – Digerkam Commented Mar 11, 2020 at 12:53
  • If you want to support URLs for multiple languages, that's the question you need to be asking. Focus on finding solutions for that specific problem, rather than the solution you've thought of, and you'll have an easier time. – Jacob Peattie Commented Mar 11, 2020 at 13:51
Add a comment  | 

2 Answers 2

Reset to default 0
add_filter('do_parse_request',function($state){

    // Here you can change every request URL by $_SERVER['REQUEST_URI']

    return $state;

},1,1);

Looks like you are trying to make the website Multilingual, so in order to achieve that, take a look at the Article on wordpress which says,

WordPress does not support a bilingual or multilingual blog out-of-the-box. There are however Plugins developed by the WordPress community which will allow you to create a multilingual blog easily. The free WPGlobus, Polylang, qTranslate-X, xili-language or Sublanguage plugins are installable on standalone WordPress sites. For multisite WordPress (one website per language), you can try Multisite Language Switcher, Zanto or Multilingual Press or purchase WPML.

You will get your routes having language code with some plugin mentioned above.

发布评论

评论列表(0)

  1. 暂无评论