Sitemap | Remove Link without $url[‘loc’]

#480662
  • Resolved Max
    Rank Math free

    Hello!

    We are currently facing an issue in our sitemap. The sitemap of a custom post type contains a link we can not manage to remove.

    We already found this filter in a previus ticket:


    $urls_to_skip = array(
    '/url/'
    );
    if ( isset( $url['loc'] ) && in_array( $url['loc'], $urls_to_skip ) ) {
    return false;
    }

    But this is not working. Probably because the url we are looking to get rid of does anyhow not have a $url[‘loc’] so the first if statement already fails. Is there any way to work around this and delete this first entry?

    Thanks for looking into this!
    Max

Viewing 12 replies - 1 through 12 (of 12 total)
  • Nigel
    Rank Math business

    Hello,

    Thank you for contacting Rank Math for help with editing your sitemap.

    If I understand correctly, you would like to delete the URL with the address https://yoursite.com/rezepte?
    The $urls_to_skip array should contain the full URL of the page to remove from the sitemap, not just the slug.

    Please modify the snippet below to work for your website by changing the URL used:

    
    add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
    	$urls_to_skip = array(
    		'https://yoursite.com/rezepte'
    		);
    		if ( isset( $url['loc'] ) && in_array( $url['loc'], $urls_to_skip ) ) {
    		return false;
    		}
    	return $url;
    }, 10, 3 );
    

    Hope that helps. Please let us know if you have questions.

    Max
    Rank Math free

    Hello Nigel,

    thank you for you reply and looking into this with me. Sadly, we already did that. Sorry, I did not make that clear in my original post, I only cut this in the code, to spare out the original URL. It does not work with the full URL.

    Nigel
    Rank Math business

    Hello,

    Thank you for your patience. We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Max
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Nigel
    Rank Math business

    Hello,

    Please may you also add the website URL to the sensitive data area so we can continue troubleshooting.

    Looking forward to helping you.

    Max
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    Please proceed with adding a full URL inside the array $urls_to_skip to exclude that certain URL.

    Then, please follow this guide to flush your sitemap cache: https://i.rankmath.com/pipRDp

    If the issue persists, please ensure that your sitemap is not heavily cached. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
    https://rankmath.com/kb/exclude-sitemaps-from-caching/

    Let us know how that goes.

    Looking forward to helping you with this one.

    Max
    Rank Math free

    Hello Jeremy, thanks for looking into this.

    The plugin-cache is disabled via
    add_filter( 'rank_math/sitemap/enable_caching', '__return_false');

    If you are logged in, no other cache interferes. Every other change to the sitemap is done immediately.

    I updated the $urls_to_skip with the full URL again, but this does not work. The URL persists in the sitemap.

    Hello,

    Allow us to further investigate this with our developers. We should get back to you shortly with an advice.

    We deeply appreciate your time and patience on this one.

    Thank you.

    Hello,

    The URL which you are trying to remove is an archive link. To remove it please use this filter: https://rankmath.com/kb/filters-hooks-api-developer/#change-remove-archive-url

    I have logged into your site and added the following code in the functions.php file:

    
    add_filter( 'rank_math/sitemap/post_type_archive_link', function( $link, $post_type ) {
    	if ('cp_recipe' === $post_type) {
    		return false;
    	}
    	
    	return $link;
    }, 10, 2 );
    

    The sitemap is not showing the /rezepte link now. Can you please confirm?

    I hope that helps.

    Max
    Rank Math free

    Hello Pratik,

    you are a hero. This is exactly what I was looking for.

    Thank you!

    Md. Sakib Khandaker
    Rank Math agency

    Hello,

    We are super happy that this resolved your issue. 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 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this ticket.