Transposh Translation Filter is a seldom updated, but very useful plugin for running multilanguage sites on WordPress. It is free, it is very intuitive to use and so far, does not appear to slow the site down too much. You can find the plugin here. Due to some differences with WordPress, the version on WordPress is outdated and no longer updated.
While the plugin creates translated page versions, the sitemaps created by the very popular Yoast SEO plugin (earlier known as WordPress SEO) don’t include those pages. The plugin documentation provides a patch that needs to be applied to the Yoast SEO plugin in the class-sitemaps.php file as follows.
/** * This function integrates with yoast sitemap generator, and adds for each viewable language, the rest of the languages url * Also - priority is reduced by 0.2 * And this requires the following patch in class-sitemaps.php * For future yoast versions, and reference, look for this function: if ( ! in_array( $url['loc'], $stackedurls ) ) { // Use this filter to adjust the entry before it gets added to the sitemap $url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $p ); if ( is_array( $url ) && $url !== array() ) { $output .= $this->sitemap_url( $url ); $stackedurls[] = $url['loc']; } }
And change to:
if ( ! in_array( $url['loc'], $stackedurls ) ) { // Use this filter to adjust the entry before it gets added to the sitemap $url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $p ); if ( is_array( $url ) && $url !== array() ) { $output .= $this->sitemap_url( $url ); $stackedurls[] = $url['loc']; } $langurls = apply_filters( 'wpseo_sitemap_language',$url); if ( is_array( $langurls )) { foreach ($langurls as $langurl) { $output .= $this->sitemap_url( $langurl ); } } } ------------------------------------------------------------------------- * @param yoast_url array $yoast_url Object containing the page information
However, on examining the code of the current version of the Yoast SEO plugin, I found that this function no longer exists at that location. With some experimentation, I found that the file inc/sitemaps/class-post-type-sitemap-provider.php needs to be edited to include the Transposh function. Find this part:
/** * Filter URL entry before it gets added to the sitemap. * * @param array $url Array of URL parts. * @param string $type URL type. * @param object $post Data object for the URL. */ $url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $post ); if ( empty( $url ) ) { continue; } if ( $post->ID === $this->get_page_for_posts_id() || $post->ID === $this->get_page_on_front_id() ) { array_unshift( $links, $url ); continue; } $links[] = $url; } unset( $post, $url ); } return $links; }
And change it to
/** * Filter URL entry before it gets added to the sitemap. * * @param array $url Array of URL parts. * @param string $type URL type. * @param object $post Data object for the URL. */ $url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $post ); if ( empty( $url ) ) { continue; } if ( $post->ID === $this->get_page_for_posts_id() || $post->ID === $this->get_page_on_front_id() ) { array_unshift( $links, $url ); continue; } $links[] = $url; /** Transposh Fix */ $langurls = apply_filters( 'wpseo_sitemap_language',$url); if ( is_array( $langurls )) { foreach ($langurls as $langurl) { $links[] = $langurl; continue; } } /** End Transposh fix */ } unset( $post, $url ); } return $links; }
Hope you find this useful.
Thanks a lot!! It works!!
Will this support with Super Progressive Web Apps plugin?
need to edite bothe filis?
you absolutely the perfect, you saved my life thank you, I was worrying about seo for other languages at alanyaturkiye.com
Wow, I have looked this for ages. Thank you very much for sharing.
You may notice already that the plugin also have hreflang problems.
1- It does not generate hreflang for self-referencing.
2- It does not generate hreflang for default language (default-x)
You have a solution for these to problems, I will appreciate if you can share. I am also working on it, but could not find any solution yet. If I find any I will post here.
Thanks
This is working great with post type and custom post type but does not give result for taxonomy, is there a solution?
the problem is that with this fix editing the core of yoast we can update any more the plugin.
Is anyway to implement this solution vía hook in functions.php?
Wow!!!! Work great with page and post .
Thanks
Tried changing inc/sitemaps/class-post-type-sitemap-provider.php on Yoast premium V11.0 and it generated a PHP error.
great article, but i guess now transpoch is more advanced, but what i believe is a good question for 2019
have you thought about how to program so it translates the schema that are produces by yoast?
hi,
Not applicable to current YOAST version, as of 14.4.2020. Is there any patch? or to time to update patch?
Sincerely.
Hi,
I found a solution, and Yoast and Transposh working together with latest plugin versions and sitemap file is working now. Prepared a quick how to.
Sincerely.
https://www.izreview.com/how-to-fix-wordpress-transposh-yoast-sitemap-problem/