exclude path from sitemap

#344648
  • Resolved Sevenhype
    Rank Math free

    Hi there,
    we need to exclude from the sitemap the posts automatically generated by the translation plugin.
    Fortunately such posts are always after /en/blog/ path.
    We tried to follow the documentation at this link

    Implementing it like this way:

    <?php
    /**
    * Filter the URL Rank Math SEO uses in the XML sitemap.
    *
    * Note that only absolute local URLs are allowed as the check after this removes external URLs.
    *
    * @param string $url URL to use in the XML sitemap
    * @param object $post Post object for the URL.
    */
    add_filter( 'rank_math/sitemap/xml_post_url', function( $url, $post){
    if (!str_starts_with($url, 'https://7hype.com/en/blog/')){
    return $url;
    }
    }, 10, 2 );

    Unfortunately, it doesn’t work.
    Where are we going wrong?

    Thanks for your help
    Matteo

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

    Thank you for contacting Rank Math and bringing your concern to our attention.

    For initial troubleshooting, please make sure that your sitemap is not getting cached. Please follow these steps:

    1. Ensure you’re using the latest version of your plugins/theme including the Rank Math plugin.

    2. Flush the Sitemap cache by following this video screencast:
    https://i.rankmath.com/xXXhDt

    3. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server:
    https://rankmath.com/kb/exclude-sitemaps-from-caching/

    If that didn’t work, could you please try this filter instead?

    add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
    	if( strpos( $url['loc'], '/en/blog/')){
    		return false;
    	}	
    	return $url;
    }, 10, 3 ); 

    Once done, flush again the sitemaps cache and check if those URLs are removed.

    I hope that helps.

    Thank you.

    Hi, thanks for the reply 🙂

    1. ok;
    2. ok;
    3. ok;

    I used the filter you mentioned above, but it seems not to be applied -> link sitemap

    On point 3 I would ask you a couple of info:

    1. the code for the htaccess, written like this doesn’t disable all the cache and not only the sitemap cache?
    2. as caching plugin we have SG optimize and in this one we have simply excluded the paths
    3. /sitemap_index.xml
      /post-sitemap.xml 
      /page-sitemap.xml

      is this correct?

    The filter is written in the rank-math.php inside the theme folder.

    Prabhat
    Rank Math agency

    Hello,

    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/

    Regarding the questions,
    1. Yes, it would only disable the cache for sitemaps.

    2. As SG Optimizer supports wild card characters, you can exclude this path: *sitemap*

    This should exclude all the URLs with the word sitemap in them.

    Looking forward to helping you.

    Hello,

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

    Thank you.

    Hello,

    The filter we have for this is to filter the URLs before they get added to the sitemap, but the TranslatePress plugin is already adding these URLs beforehand so when the filter tries to parse them it no longer can modify them.

    To get around this issue the only way is to completely disable the language sitemaps with the following filter:

    
    add_filter('trp_disable_languages_sitemap', '__return_true');
    

    Hope this helps clarify your doubts.

    Don’t hesitate to get in touch if you have any other questions.

    Hi Miguel,
    thanks for the support.
    Is it possible to limit the filter to the post type only, in order to have the pages with the multilingual sitemap and the post type mono language?

    thanks
    Matteo

    Hello,

    Looking at the source code of TranslatePress it seems that the filter we mentioned can be passed a function with a mixed variable called $allow and maybe this one can be used to exclude only certain portions from the sitemap.

    Since this is a filter specific to TranslatePress, could you please get in touch with them and ask about the possibility of only running this filter for a specific post type?

    Don’t hesitate to get in touch if you have any other questions.

    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 7 replies - 1 through 7 (of 7 total)

The ticket ‘exclude path from sitemap’ is closed to new replies.