Sitemap TranslatePress exclude URL

#210433
  • Resolved Robin
    Rank Math free

    Hello, we use TranslatePress, but we do have pages that are specific to certain languages.
    I want to remove the urls that are created that we dont want from the sitemap.

    For example, I create the page /marketing-united-states/
    Now TranslatePress creates /sv/marketing-united-states/ as well and adds it to the sitemap. On the frontend we just redirect the page to /sv/. But of course it is still added to the sitemap.

    What I tried:

    add_filter( 'rank_math/sitemap/xml_post_url', function( $url, $post){
    if('https://<domain>/sv/marketing-united-states/' !== $url) {
    return $url;
    }
    }, 10, 2 );

    This did not work, it did work however when trying with a default language page. That indicates that the entries added to the sitemap for the translated pages somehow overwrite the above filter.

    Do you have any ideas what we can do to hide these translated entries?
    The solution needs to account for when the page is only in one of the translated languages as well, for example:

    /marketing-stockholm/ <- be able to remove from sitemap
    /sv/marketing-stockholm/ <- be able to keep in sitemap when above is removed

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    Thanks for contacting us. Sorry for the delay and any inconvenience that might have been caused due to that.

    By default, Rank Math doesn’t add the translated posts or pages into the sitemap. Can you please confirm if you are using the SEO Pack add-on of TranslatePress? If yes then the translated pages are being added in your sitemap due to that add-on. Please check, there should be an option to disable this. You can also refer to this link for more details: https://translatepress.com/docs/addons/seo-pack/

    Hope this helps. Let us know if you need any further assistance.

    Robin
    Rank Math free

    Hello

    Yes we decided to go an alternate route and just disable the setting in TranslatePress and adding custom entries to the sitemap for the URLs we want.

    We’ve ran into another problem though regarding adding the custom URLs with ACF.
    So far I’ve got this code and it does not work, do you know how this could be improved?

    add_action( 'rank_math/sitemap/page_content', function() {
    	$urls = '';
    
    	$sitemap_custom_entries = get_field('sitemap_custom_entries', 'option');
    	if ($sitemap_custom_entries) {
    		foreach ($sitemap_custom_entries as $u) {
    			$urls .= '<url>
    				<loc>' . $u['url'] . '</loc>
    				<lastmod>' . $u['date'] . '</lastmod>
    			</url>';
    		}
    	}
    
    	return $urls;
    });
    Robin
    Rank Math free

    Nevermind, for some reason the following below worked. Leaving last reply up incase others stumble upon this.

    add_action( 'rank_math/sitemap/page_content', 'rank_math_add_custom_dynamic_url'); 
    function rank_math_add_custom_dynamic_url() {
    	$urls = '';
    
    	$sitemap_custom_entries = get_field('sitemap_custom_entries', 'option');
    	if ($sitemap_custom_entries) {
    		foreach ($sitemap_custom_entries as $u) {
    			$urls .= '<url>
    				<loc>' . $u['url'] . '</loc>
    				<lastmod>' . $u['date'] . '</lastmod>
    			</url>';
    		}
    	}
    
    	return $urls;
    }

    Hello,

    We are super happy that your issue is resolved. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

You must be logged in to reply to this ticket.