Rewrite sub folder dynamically with country code in WordPress using PHP
-
I have been working on a client site. There are two similar sites, one for their own country and second for other countries visitors.
Their main site hosted in the root of server and second site hosted in the sub folder.
Now what I want is dynamic url rewrite for second site which is hosted into sub folder with the country code of the visiting user.
For e.g.
https://example.com
<br>
https://example.com/subfolder/
are the urls.
I want this
https://example.com/subfolder/
to be changed into thishttps://example.com/country_code/
wherecountry_code
is visitor country code in ISO format getting through php function.So if user is from United States the
subfolder
must be changed intous
, the new url should be nowhttps://example.com/us/
.I want this to work for all type of pages, whether its a page, post, category, tag or author page.
So again,
https://example.com/subfolder/any-type-of-url/
=>https://example.com/country_code/any-type-of-url/
Remember
country_code
is user/visitor country code in ISO format.Let me know if someone needs more information on this. Thanks in Advance.
PS: I tried to achieve this using
add_rewrite_rule()
function available in WP.
- The topic ‘Rewrite sub folder dynamically with country code in WordPress using PHP’ is closed to new replies.