Support » Plugin: Custom Permalinks » Issue with Polylang Setting “Hide Default Language”

  • Hi,

    Im currently developing a site locally that will use the Polylang plugin for localization. The site already uses the Custom Permalinks plugin for quite a few posts. So far everything is working great except one setting in Polylang: Hide Language on Default Language. We want to use the “subfolder” url structure for our translated pages. For example the homepage for our translated pages would look like:

    But do not want the subfolder for the default language (in our case English). Polylang has a setting that allows this so the English homepage would be:

    The issue Im running into is in the file class-custom-permalinks-form.php line 518 removes the lang assuming the path looks something like fr/foo/bar and the result is foo/bar/. Where this fails is when we have checked the option to hide the lang on the default language so when our English page paths get past to this function they do not have the language code “en” in the url so what happens is this: the
    function gets /foo/bar/ and the result is bar/. Thus we get a 404 on that page. Given there is no filter for this I have tested the following in the plugin file itself and all works.

       * Check Conflicts and resolve it (e.g: Polylang)
       * UPDATED for Polylang hide_default setting
       * @access public
       * @since 1.2
       * @return string
      public function custom_permalinks_check_conflicts( $requested_url = '' ) {
        if ( '' == $requested_url ) {
        // Check if the Polylang Plugin is installed so, make changes in the URL
        if ( defined( 'POLYLANG_VERSION' ) ) {
          $polylang_config = get_option( 'polylang' );
          if ( $polylang_config['force_lang'] == 1 ) {
            if ( false !== strpos( $requested_url, 'language/' ) ) {
              $requested_url = str_replace( 'language/', '', $requested_url );
            // get current language
            $current_language = pll_current_language();
            // get defualt language 
            $default_language = pll_default_language();
             * Check if hide_defualt is true and the current language is not the default.
             * If true the remove the  lang code from the url.
            if (( $polylang_config['hide_default'] == 1 && $current_language !== $default_language ) ) {
              $remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
              if ( '' != $remove_lang ) {
                return $remove_lang;
        return $requested_url;

    Is this something that can be updated in the next plugin release or am I missing something that is already in place for this case?

    • This topic was modified 4 years, 10 months ago by mikerojas.
    • This topic was modified 4 years, 10 months ago by mikerojas. Reason: Typo fixes and added some text formatting
Viewing 1 replies (of 1 total)
  • Plugin Author Sami Ahmed Siddiqui


    Hi @mikerojas

    Sorry for the delay in my response. I have checked and modified your provided code to fulfill the functionality either the hide_default is true or false.

    Please test this issue in v1.5.0 and let me know your thoughts on it.


Viewing 1 replies (of 1 total)
  • The topic ‘Issue with Polylang Setting “Hide Default Language”’ is closed to new replies.