colin
colin

Reputation: 425

Wordpress | Yoast SEO - Change slug or fragment in XML sitemap

Problem Yoast SEO generates XML sitemap with links that lead to 404 errors.

Because I'm using WPML and some str_replace scripts in my functions.php to rewrite slugs/permalinks. The XML sitemap generator by Yoast SEO is not using those scripts in my functions.php, so it generates non-valid links.

My str_replace scripts is changing the custom post type slug:

English domain.com/news/taxo_en1/taxo_en2/title

Dutch domain.com/nl/nieuws/taxo_nl1/taxo_nl2/titel

And the XML Sitemap is showing this Dutch domain.com/nl/news/taxo_nl1/taxo_nl2/titel

Is there a way to change the generated links in the XML sitemap? With a wpseo_do_sitemap hook or?

Upvotes: 0

Views: 1684

Answers (1)

Mike
Mike

Reputation: 11

Maybe this will help someone else, i have found this filter:

function filter_wpseo_sitemap_entry( $url, $term, $term ) { 

return str_replace("string to search", "string to replace", $url);

}

add_filter( 'wpseo_sitemap_entry', 'filter_wpseo_sitemap_entry', 10, 2 );

It will generate new links when post is updated / saved

Best regards Mike

Upvotes: 1

Related Questions