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?

2
  • Which plugin you have used Commented Jan 27, 2020 at 11:49
  • Redirection plugin by John Godley
    – Marco V
    Commented Jan 27, 2020 at 11:53

1 Answer 1

3

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; 
    }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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