1

I want to redirect my site to the correct url based on parameter. The url is passed when changing the language of the site using the language switcher.

If url contains lang=de, then redirect to example.com/de/ If url contains lang=es, then redirect to example.com/es/

I've tried using the Redirection plugin by John Godley but I'm not sure how to set it up.

What's the best way to get this done?

  • Which plugin you have used – Ankush Kumar Jan 27 at 11:49
  • Redirection plugin by John Godley – Mike. D Jan 27 at 11:53
2

You can use wp_redirect with something like...

add_action( 'init', 'my_redirect');
function my_redirect() {
    if (get_query_var('lang') == "de") {
        wp_redirect( site_url('/de/') ); 
        exit; 
    }   
}
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.