I want to add country code to wordpress url by getting user ip address, which should be implemented dynamically. For example if user is from Australia, all website url will be like below: http://test.com/au htttp://test.com/au/contact

For example if user is from USA, all website url will be like below: http://test.com/us htttp://test.com/us/contact

  • 1
    so you want to redirect users to their country code URLs? Note you'll need a GeoIP service or database for the mappings which WP doesn't provide, and IPs aren't a reliable indicator of origin. Ignoring obvious things such as VPNs, people travel, companies use proxies, ISPs re-route traffic ( a popular way to control roaming costs for mobile users is to route traffic back to the operators country so they can throttle and apply charges ). It will also be incompatible with caching, and CDNs, and you'll need to consult with CDNs such as cloudflare for bucketing and if they provide geo-location
    – Tom J Nowell
    Oct 5 '21 at 12:09
  • Actually the ip and the getting country code is not the problem. But after getting the country code like , au, how can we implement it to wordpress url (not using any plugin : may be using like rewrite rules of wordpress)
    – prayas
    Oct 5 '21 at 16:01
  • it will involve a redirect of some sort, do you have separate posts already? If it's exactly the same site content etc identical in every way except the addition of this country code to the URL then you're going to face heavy SEO penalties, but you also need to tell us as it makes a huge difference to what kinds of answers will work. Provide as much context as you possibly can
    – Tom J Nowell
    Oct 5 '21 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.