Changing language issue

Changing language issue

When we change the language of the site while trying to add an event to our website, a 404 error message appears. However, this issue is now fixed with a simple code that needs to be pasted in the function.php. Now the error message does not appear while adding an event after changing the language. Or you can create a child theme and paste the code in the child theme’s function.php

Here is the code

  1. add_action('init', function() {
  2. ​    if (is_admin()) {
  3. ​        return;    
  4. ​} 
  5.     $current_locale = get_locale();
  6. ​    $flushed_locale = get_option('last_flushed_locale');     
  7. ​if ($current_locale !== $flushed_locale) {
  8. ​        flush_rewrite_rules(false);
  9. ​        update_option('last_flushed_locale', $current_locale);
  10. ​    }
  11. ​});