• Resolved nervus70

    (@nervus70)


    Hello

    When I go to my sitemap:

    http://MYWEBSITE/sitemap.xml

    it’s fine.

    But if I want to show my sitemap in another language like “fr”, like this:

    http://MYWEBSITE/sitemap.xml?lang=fr

    The generated links are at this format:

    http://MYWEBSITE?lang=fr/sitemap-home.xml

    Witch is wrong.

    I fixed it by modifying the function “get_index_url()”

    Old code:

    public function get_index_url( $sitemap = 'home', $type = false, $param = false )
    	{
    		$root =  esc_url( trailingslashit(home_url()) );
    		$name = $this->base_name.'-'.$sitemap;
    
    		if ( $type )
    			$name .= '-'.$type;
    
    		if ( '' == get_option('permalink_structure') || '1' != get_option('blog_public')) {
    			$name = '?feed='.$name;
    			$name .= $param ? '&m='.$param : '';
    		} else {
    			$name .= $param ? '.'.$param : '';
    			$name .= '.'.$this->extension;
    		}
    
    		return $root . $name;
    	}

    New code:

    public function get_index_url( $sitemap = 'home', $type = false, $param = false )
    	{
    		$split_url = explode('?', home_url());
    		$query_string_lang = (isset($split_url[1]) ? $split_url[1] : '');
    		$home_url = $split_url[0];
    
    		$root =  esc_url( trailingslashit($home_url) );
    
    		$name = $this->base_name.'-'.$sitemap;
    
    		if ( $type )
    			$name .= '-'.$type;
    
    		if ( '' == get_option('permalink_structure') || '1' != get_option('blog_public')) {
    			$name = '?feed='.$name;
    			$name .= $param ? '&m='.$param : '';
    			return $root . $name . '&' . $query_string_lang;
    		} else {
    			$name .= $param ? '.'.$param : '';
    			$name .= '.'.$this->extension;
    			return $root . $name . '?' . $query_string_lang;
    		}
    
    	}

    Please fix it in the next version 🙂

    Thank you

    https://wordpress.org/plugins/xml-sitemap-feed/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Which multilanguage plugin are you using?

    Thread Starter nervus70

    (@nervus70)

    WPML

    OK, interesting. I’m trying to improve WPML compatibility but since I don’t have the plugin and the WPML developers are not telling me everything (I think, or I’m not asking the right questions) I’m working in the dark. Your experience and feedback might help me further 🙂

    Does your site have all French posts only accessible via ?lang=fr after the URL or also via /fr/ inside the URL?

    Thread Starter nervus70

    (@nervus70)

    Indeed only via ?lang=fr 🙂

    Thread Starter nervus70

    (@nervus70)

    If you prefer asking questions live, I’m available on skype: Nervus70
    Thank you for your help

    That’s very kind of you, I might take you up on that later. I should be able to revive my old Skype account 😉

    In the mean time, I’ve got a development version (4.7 alpha) on https://github.com/RavanH/xml-sitemap-feed with a variant of you split code implemented, plus another WPML compatibility addition which has not been tested yet. The addition is supposed to cause all languages to be present in the sitemaps, instead of only the default. But because I don’t have WPML, I cannot verify this.

    Could you download it (button Download ZIP on the right) extract and overwrite current plugin files by FTP?

    If you have a development version of your site, you might want to test it there. It’s an alpha release after all 🙂

    Hi @mervus70 – version 4.7+ should be fully compatible with WPML. Please let me know if you find any issues 🙂

    Thread Starter nervus70

    (@nervus70)

    Hi,

    Sorry I was on holiday for 2 weeks.
    Thank you a lot for your reactivity, we will update and test the plugin ASAP.

    I keep you posted

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Bug with query string param ?lang=’ is closed to new replies.