For one particular page on my site I would like to append the country to the URL. The reasons for this are purely aesthetic so the customer knows that the prices on that page are in their own currency where their currency name/symbol is the same as others e.g. $ - USD, AUD, NZD etc
So the URL should be example.com/signup/nz
or example.com/signup/au/
. Each signup/<countrycode>/
then displays the same page (example.com/signup/
) which handles the logic to display the correct prices/currencies for the users country. I'm not too worried if the home page also has /<countrycode>/
appended also but didn't want to append it across the entire site (at this stage).
I have a couple of questions related to this after looking at a number of articles on here.
I believe I should be using
add_rewrite_rule
to achieve this - is this correct? I've tried a few combinations of this and navigating directly to/signup/nz/
(for example) just displays the 404 page (I am saving permalinks when I update the rewrite_rule). The rule I've mainly tried came from https://wordpress.stackexchange.com/a/252843 which I changed to the below:add_rewrite_rule('^signup/([^/]*)/','index.php?pagename=signup&country=$matches[1]','top');
and also triedadd_rewrite_rule('^signup/([^/]*)/','index.php?pagename=signup','top');
How do I get the site to automatically append this when the page itself is navigated to? e.g. if I'm on the home page and click the signup button do I need to on the home page geolocate the customer and have the href for the signup button updated for the customers location (e.g. to say the link is
signup/nz/
orsignup/gb/
) or is this done somehow in the page?
From the reading that I've done if the above is the correct way to do this I believe there may be problems with duplicate content for SEO etc by doing this. I think I can get around this by adding the canonical name to the signup page. Is my thinking correct?
$_GET
for anything in the query string, so if your URL ishttp://example.com/?country=india
you would access$_GET['country']
to find out that "india" has been requested.