[Resolved] Yoast WordPress SEO sitemap.xsl error

Home Support English Support [Resolved] Yoast WordPress SEO sitemap.xsl error

This topic contains 4 replies, has 5 voices, and was last updated by  koenD 1 week ago. The support staff assigned to this topic is Bruno.

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
October 30, 2013 at 5:35 pm #284531

Zach

I just want to log this somewhere so that it can help others.

As of v1.4.19 of Yoast WordPress SEO plugin, the global constant of "WPSEO_FRONT_URL" has been removed. This is a critical piece to forming the correct url for the {sitemap.xsl} url on any generated {sitemap.xml} page.

Simple enough fix for the primary domain is to redefine the constant in some form in the active theme {functions.php} file. For example:

define('WPSEO_FRONT_URL', 'wpdir/wp-content/plugins/wordpress-seo/');

But that only gets part of the issue fixed. If your site uses multiple domains for the additional languages, you'll then need to open {plugins/sitepress-multilingual-cms/inc/wpseo-sitemaps-filter.php} and replace lines 130-147 with the following:

    /**
     * Filters XML sitemap stylesheet
     */
    function set_stylesheet(){
    	global $sitepress_settings;

    	if(@$sitepress_settings['language_domains'][$this->get_sitemap_language()]){
	    	$language_domain = $sitepress_settings['language_domains'][$this->get_sitemap_language()];
			$wpseo_dirname = str_replace('wp-seo.php', '', WPSEO_BASENAME);
			//$wpseo_domain_path = $language_domain . '/wp-content/plugins/' . $wpseo_dirname;

			/*$this->stylesheet = '<?xml-stylesheet type="text/xsl" href="'.$wpseo_domain_path.'css/xml-sitemap.xsl"?>';*/
    		$this->stylesheet = '<?xml-stylesheet type="text/xsl" href="'.$language_domain.'/'.WPSEO_FRONT_URL.'css/xml-sitemap.xsl"?>';
    	} else {
    		$this->stylesheet = '<?xml-stylesheet type="text/xsl" href="'.WPSEO_FRONT_URL.'css/xml-sitemap.xsl"?>';
    	}

    	return $this->stylesheet;
    }

This should keep everything in check. Hope this helps someone.

October 30, 2013 at 7:57 pm #284580

Bruno
Forum moderator

Dear Zach,

Thanks for sharing your code. It is truly appreciated.

Thank you.

December 18, 2013 at 9:19 am #310112

Vincent

It doesn't fix the problem on my website… :(

http://www.rodcraft.com/sitemap_index.xml

Please help !

February 26, 2014 at 6:52 pm #348111

Chitu Okoli

I had the same problem. Vincent: Do you still have the problem? Your sitemaps in English and Deutch seem to both be working OK.

I refactored Zach's code above to a much simpler situation for sites with multilingual domain names.

For this solution, the WPSEO_FRONT_URL definition in functions.php is completely unnecessary. Zach's solution is great, and better than mine if you only have one domain name for all languages. However, if you need to change WPML core files because you have multilingual domain names, then proceed:

In /plugins/sitepress-multilingual-cms/inc/wpseo-sitemaps-filter.php, completely replace function set_stylesheet() with this code:

    function set_stylesheet(){
    	global $sitepress_settings;
    	
	$wpseo_path = wp_make_link_relative( plugins_url() ).'/wordpress-seo/'; // WP SEO plugin path without domain
	$this->stylesheet = '<?xml-stylesheet type="text/xsl" href="'.$wpseo_path.'css/xml-sitemap.xsl"?>';

    	return $this->stylesheet;
    }

That's it. This works for my multilingual domains.

However, I don't understand the "$wpseo_dirname = str_replace('wp-seo.php', '', WPSEO_BASENAME)" code in the original function, so there might be some setups where this code doesn't work.

It would be great if WPML could update the core with fixed code in response to Yoast's dropping of the WPSEO_FRONT_URL constant.

April 16, 2014 at 8:58 am #381621

koenD

Isn't it a bit strange that we need to "hack" the WPML code to get the sitemaps working?

Anyway, it seems like that the xsl isn't anymore in the plugin directory (…./css/xml-sitemap.xsl), but in the root: yourdomain.com/main-sitemap.xsl (at least at my wordpress install)?

This fixed the xsl error:

$this->stylesheet = '<?xml-stylesheet type="text/xsl" href="'.home_url().'/main-sitemap.xsl"?>';
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.