We have a website with around a hundred pages, and each has been localized into 3 languages using the WPML plugin. We would like to try disabling localization for several weeks. In doing so, we have the following requirements:

  • Existing translations should not be deleted
  • Requests resolving to existing non-English pages should 302 to their English versions
  • Language picker does not appear
  • <link rel="alternate" hreflang="..."> tags for non-English languages are not included in the <head>

Two options I've considered already, and why they aren't 100%:

  1. Disabling the WPML plugin: this meets all the requirements except for providing 302 redirects.
  2. Using the WPML configuration to hide the non-English languages, and to disable the current language from appearing in the Language Switcher. Since the other languages are hidden, this prevented the Language Switcher from appearing. This approach achieved the same results of the first, and did so in a cleaner manner (it preserved the maintainability of the existing translations), however, I still did not find a way to enable 302 redirects from the localized pages to their English equivalents.

I'm thinking that a simple implementation could look like the following:

  1. Leave the WPML plugin active
  2. Leave the non-English languages enabled (not hidden)
  3. Disable/delete the Language Switcher in the WPML configuration
  4. Using WP/WPML APIs, add a hook action in my theme's functions.php to listen for requests for localized pages, and if found, redirect them to their English equivalent. I'm a noob in WP/WPML, so here's my naive attempt:

    function redirect_localized_page_to_default_language( $query ) {
        if ( 'post_page' == $query->query_vars['post_type'] && ICL_LANGUAGE_CODE != 'en' ) {
            wp_redirect( /* URL for the page's default language */ );
        return $query;
    add_action( 'parse_request', 'redirect_localized_page_to_default_language' );

I'm unsure how sane this approach is, and I also can't find anything in the WPML API to get a translation's URL (wpml_get_element_translations seems to be the closest thing, but it does not provide any URL information). Any hints will be appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.