url rewriting – WPML preserve parameter as part of URL


I have a page “Job”: www.example.com/job/. The URL takes an id parameter to receive data from an API that is displayed on the page like: www.example.com/job?id=1000

To make the URL more appealing I use the following code to enable www.example.com/job/1000 to load as www.example.com/job?id=1000

add_action('init', function(){
  add_rewrite_rule('^job/([^/]+)([/]?)(.*)', 'index.php?pagename=job&id=$matches[1]', 'top');
add_filter('query_vars', function( $vars ){
  $vars[] = 'id';
  return $vars;

In WPML, when visiting www.example.com/job?id=1000 the language switcher will correctly link to www.example.com/job/?lang=fr&id=1007

When visiting www.example.com/job/1000 the language switcher will only link to www.example.com/job/?lang=fr

How can I achieve WPML to retain the parameter in its language swticher if its part of the URL instead of a classic GET param?

Kevin Grabher 11 months 2022-03-07T20:27:30-05:00 0 Answers 0 views 0

Leave an answer