Viewing 9 replies - 1 through 9 (of 9 total)
  • Hmmm, the sitemap should contain all languages so it looks like it is incompatible with WPML. I do not have WPML to test with so I fear I cannot make it compatible either.

    Maybe the WPML developers can say something more about it?

    I have made this plugin compatible with WPML doing some changes in 2 files. I use this plugin instead of YOAST’s xml (or others) because with these changes I can populate all languages stemming from a single xml sitemap, which is good to combine with W3 Total Cache because W3 Total Cache uses a single XML sitemap to prime all cached posts & pages.

    I’ll post the changes here, hopefully they’ll be understandable to @RavanaH (it’s heavily indented). The idea is to check for global variable $sitepress in addition to $polylang and then do the logic there. Also, in the sitemap index, include the other languages.

    XML SITEMAPS FEED
    =================

    /wp-content/plugins/xml-sitemap-feed/includes/core.php

    added support for WPML language urls settings, not just polylang. This will affect everywhere where there is polylang stuff.

    line 378 | function is_home($id) Where it checks for global $polylang, we change the code to this:

    global $polylang;
    	global $sitepress;
    	if ( isset($polylang) ){
    		$this->blogpage = $polylang->get_translations('post', $blogpage);
    	}else if(isset($sitepress)
    			&& function_exists('icl_xml_post_languages')){
    		$this->blogpage = icl_xml_post_languages('post', $blogpage);
    	}
    	else
    		$this->blogpage = array($blogpage);

    line 625 | function get_home_urls() Where it checks for global $polylang, we change the code to this:

    global $polylang, $q_config, $sitepress;
    
    	if (isset($polylang)) {
    		foreach ($polylang->get_languages_list() as $term)
    			$urls[] = $polylang->get_home_url($term);
    	} else if (isset($sitepress)
    			&& function_exists("icl_get_languages")) {
    		$iclLanguages = icl_get_languages('skip_missing=1');
    		if (!empty($iclLanguages)) {
    			foreach ($iclLanguages as $iclLang) {
    				if ($iclLang['active']) {
    					$urls[] = $iclLang['url'];
    				}
    			}
    		} else {
    			$urls[] = icl_get_home_url();
    		}
    	} else {
    		$urls[] = home_url();
    	}

    line 645 | function get_excluded($post_type) here it checks for global $polylang, we change the code to this:

    global $polylang, $sitepress;
    	if (isset($polylang)) {
    		$exclude += $polylang->get_translations('post', $id);
    	} else if (isset($sitepress)
    			&& function_exists("icl_xml_post_languages")) {
    		$exclude += icl_xml_post_languages('post', $id);
    	} else {
    		$exclude[] = $id;
    	}

    /wp-content/plugins/xml-sitemap-feed/includes/feed-sitemap.php

    Before
    </sitemapindex>
    add into the index sitemaps the sitemap indexes corresponding to every language.

    // language specific sitemaps appear only in default language.
    // Otherwise W3 Total Cache enters an infinite loop
    
    global $sitepress;
    if (isset($sitepress)
    		&& function_exists(icl_get_languages)):
    	if (icl_get_current_language() == icl_get_default_language()):
    		$iclLanguages = icl_get_languages('skip_missing=1');
    
    		if (!empty($iclLanguages)):
    			foreach ($iclLanguages as $iclLang):
    				if (!$iclLang['active']):
    					?>
    					<sitemap>
    						<loc><?php echo $iclLang['url'] . 'sitemap.xml'; ?></loc>
    						<lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', get_lastdate('gmt'), false); ?></lastmod>
    					</sitemap>
    					<?php
    				endif;
    
    			endforeach;
    		else:
    			$urls[] = icl_get_home_url();
    		endif;
    	endif;
    
    endif;

    That should be it

    Hi @hermes3por3 that’s excellent work! So you’ve got this running with the latest WordPress and WPML? I don’t have WPML so I’ll have to rely on your experience ??

    Do you have an account on Github? If so, you can fork https://github.com/RavanH/xml-sitemap-feed to apply your patch and create a pull request.

    Hi, yes I’ve got it running with the latest. I’ll try the github and will let you know.

    I have tested your branch WPMLcompat and it works perfectly with WPML and W3 Total Cache!

    Hi Hermes, good, that branch has your code merged. Can you share a link to the resulting sitemap? And did you test the google news sitemap?

    @markuz05 version 4.7+ should be fully compatible with WPML. Please let me know if you find any issues ??

    @hermes3por3 thank you very much for your input and feedback. Even though I chose a different approach (which works for Google News sitemap too) in the end, you’ve been a tremendous help pushing me forward for WPML compatibility! ??

    Hi Hermes and RavanH,

    I also have problems with different WPML language versions of pages that are not showing up in the xml sitemaps. The version of the plugin is the right now latest version 4.7.1.

    To this version, I would like to apply the above shown code. So I wanted to copy and paste the above shown code, but in my installed version i.e. there is no file “/wp-content/plugins/xml-sitemap-feed/includes/core.php”.

    So how can I apply these changes? Will there be an update to the official plugin, including the above shown code?

    Thanks for your answer!

    Hi Tom, the patch provided above is only for version 4.6.3 and below. If you want, you can download that version from https://www.ads-software.com/plugins/xml-sitemap-feed/developers/ under Other Versions but the current 4.7 should be WPML compatible. If you are having trouble with in combination with WPML, please open a new thread and provide a link to your sitemap if you can.

    Or you can contact me directly via https://status301.net/contact-en/

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘xml-sitemap-feed & WPML’ is closed to new replies.