Support » Plugin: WP Better Permalinks » WPML compatibility

  • Hi,

    This is David from the WPML compatibility team.

    We recently had a support request at WPML about your plugin working together with ours:

    https://wpml.org/forums/topic/wp-better-permalinks-with-wpml-taxonomy-translation/

    The problem shows up only if we set the language URL format to use subdirectories. WordPress rewrite rules shouldn’t include the language folder but your plugin is including it.

    We could resolve it by adding a few lines functions/posttypes/rewrites.php around line 32 we have:

            $list = [];
     
            foreach ($this->core->posttypes->options['posts'] as $rewrite)
               $list[$rewrite['regex'] . '/?$'] = $rewrite['path'];
     
            $wp_rewrite->rules = $list + $wp_rewrite->rules;

    Replace it with this:

           $list = [];
    
           foreach ($this->core->posttypes->options['posts'] as $post_id => $rewrite) {
              $lang = apply_filters('wpml_element_language_code', null, array('element_id' => $post_id, 'element_type' => get_post_type($post_id)));
              $home_url = apply_filters('wpml_permalink', home_url(), $lang);
              $path = substr(trailingslashit(parse_url($home_url, PHP_URL_PATH)),1);
              $rewrite['regex'] = preg_replace("~^$path~", '', $rewrite['regex'], 1);
              $list[$rewrite['regex'] . '/?$'] = $rewrite['path'];
           }
     
           $wp_rewrite->rules = $list + $wp_rewrite->rules;

    What this does is to remove the language folder from the rewrite rules.

    I am sharing this here so you can make that change in your plugin and give our shared users a smoother experience.

    Best,
    David

Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.