Prepend a country code to the beginning of all URLs in WordPress

I have a WP question hoping someone can point me in right direction.

I have a WordPress site that allows users to switch regions — they still see the same pages/menus but the content is different depending on the region they selected.

Read More

Now, I would like to display the region at the root of the URL, for example:

http://website.com/au/hello-world/

http://website.com/us/hello-world/

Essentially the first part of the URL will do nothing other than indicate the country they are currently viewing.

I found this question which was similar, but OP ended up using a plugin which I want to avoid.

I see a lot of info about using the query_vars filter to the end of a URL as a way of passing parameters in a clean way, but they all seem to assume you want the param to be at the end of the URL rather than the beginning.

Related posts

1 comment

  1. Depending on what you are really after with this, you might try a translation plugin like WPML. You could than “translate” (or in your case just adpat) the content for the specific regions. Seems like the most straight-forward solution to me.

Comments are closed.