Pages showing in sitemap that should not be indexed

#620631
  • Resolved Doug Demagistris
    Rank Math free

    Hello –

    We have two pages showing up in the Rank Math XML sitemap that should not be indexed in search engines. We cannot remove them because these pages do not have POST/PAGE ID.

    We have used the Rankmath hooks to make these two pages no index and no follow.
    https://rankmath.com/kb/filters-hooks-api-developer/

    But these pages are still being displayed on the generated Sitemap.

    How can we remove them?

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math support and we apologize for the inconvenience.

    We can see from your page source that these pages have already been set to noindex – but they are still showing up on your sitemaps. Have you tried flushing and regenerating your sitemap? Watch this screencast to do that: https://i.rankmath.com/pipRDp

    That said, you can actually use the rank_math/sitemap/entry filter to forcefully remove the URLs from your sitemap. You can learn more about the filter here: https://rankmath.com/kb/filters-hooks-api-developer/#filter-sitemap-item

    Here’s an example code, you can add to remove both URLs:

    add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
    	// List of URLs to exclude
    	$exclude = array(
    		'https://seasoft.com/products/',
    		'https://seasoft.com/solutions/'
    	);
    
    	// Check if the URL is in the exclude list
    	if ( in_array( $url['loc'], $exclude ) ) {
    		// Return false to skip this URL
    		return false;
    	}
    
    	// Return the original URL otherwise
    	return $url;
    }, 10, 3 );

    Try this and let me know if it worked for you. Thank you for choosing Rank Math!

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Pages showing in sitemap that should not be indexed’ is closed to new replies.