How to exclude portfolio archive in sitemap.xml

#611075
  • Resolved Anonymous
    Rank Math free

    Hello,
    I have been using Rank Math plugin as my SEO tool together with Avada theme. I have been struggling with a problem about portfolio archive. Normally in my website, I do not use archive pages as this is a corporate page, not a blog. However, RankMath sitemap includes my portfolio archive page in the list. I cannot manually edit the page and make it “noindex” as there is no page like this. When I access the page on browsers the page exists, no 404 errors. I tried to make noindex at the top of page in wordpress bar by RANK MATH SEO>mark this page>as NoIndex. It puts a tick, but there is no change in the result.

    Can you please help me about this issue. I am not sure if it is about your plugin or Avada theme. I searched for Avada options to disable but couldn’t find there too. Thanks.

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

    Thank you for getting in touch and we are sorry to hear about the issue you are facing.

    You can exclude Post types/Taxonomies by going to your WordPress Dashboard > Rank Math SEO > Sitemap Settings. If it’s a Post Type, it should be under the Post Type category:

    Rank Math support

    However, if you don’t see it there, then you would need to apply a filter code since this is a dynamically generated archive page. Please refer to the code below:

    add_filter('rank_math/frontend/robots', function ($robots) {
    	$url = home_url($_SERVER['REQUEST_URI']);
    	if (strpos($url, '/aduro') !== false) {
    		$robots['index'] = "noindex";
    		$robots["follow"] = 'nofollow';
    		return $robots;
    	}
    	return $robots;
    });

    You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

    Anonymous
    Rank Math free

    Thanks for solution. However, I still see the archive link in the sitemap created by Rank Math.
    I applied to filter to a new created file rank-math.php under theme folder as explained in the link you have shared.
    Does the code only prevent the robots from indexing? Or should it also supposed to solve the problem with the dynamically created XML sitemap by Rank Math?

    Hello,

    In that filter, the archive pages would be set to noindex when they load in the browser.

    However, if you wanted to remove them from your sitemap manually, please try the filter in the sensitive data section instead.

    Once done, follow the steps in this link to flush the sitemap cache:

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

    2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. 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/

    And add this filter to your active child/theme’s functions.php file:

    add_filter( 'rank_math/sitemap/enable_caching', '__return_false');

    Hope that helps.

    Thank you.

    Anonymous
    Rank Math free

    Hello again,
    Thanks for your support. Sorry but still doesn’t work for me. I am not an experienced user, I tried to do everything as explained but maybe I do some part wrong.

    First filter caused my 76 pages to be noindex and nofollow. Because all my portfolio pages starts with the url I listed in sensitive data. Filter blocked not only that URL but also all the rest starting with that URLs

    Second filter, I used the following row in my rank-math.php as explained in the support links. Does it make a difference to use them in functions.php of child theme?
    add_filter( ‘rank_math/sitemap/enable_caching’, ‘__return_false’);

    Hello,

    The filter in the sensitive data section should only exclude the URLs mentioned, and not set them to noindex.

    Also, applying the filter in either the rank-math.php file or your child theme’s functions.php file should work.

    If you want, we can apply the filter on your site to ensure that they are working properly.

    To do that, 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.

    Thank you.

    Anonymous
    Rank Math free

    Hello,

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

    Thank you.

    Hello,

    Thank you for your patience.

    I’ve checked your sitemaps, and the /en/ and /fr/ archive URLs were already removed by using the filter I have previously shared. But the main site archive is still included as this is the default behavior of the sitemap.

    However, I have already applied the filter below to exclude that specific URL from your portfolio sitemap

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

    You can now check the sitemap as well as those portfolio archive URLs are already removed.

    Hope that helps.

    Anonymous
    Rank Math free

    Thanks for this great support. It works fluently. Unlike your statement, the /en/ and /fr/ archive URLs were never indexed at XML sitemap, even before asking this problem to support. I am not sure if we delete the old filter, RankMath plugin will put them in to XML index.
    Moreover, can you please check if it is possible also to make noindex for those three archive pages. The previous filter you have sent, immediately put noindex to all of my portfolio pages. So, 76 pages were alerted to be noindex.

    Hello,

    Apologies for the inconvenience with that option.

    However, to set those archive pages to noindex, I have added this filter in your rank-math.php file:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
         if(is_post_type_archive('avada_portfolio')){
             $robots['index'] = "noindex";
             $robots['follow'] = "follow";
         }
    	return $robots;
    });

    This affects only the archive of the portfolio, and they are removed from your sitemap as well.

    Looking forward to helping you.

    Anonymous
    Rank Math free

    Thanks for all. Really perfect support!

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

The ticket ‘How to exclude portfolio archive in sitemap.xml’ is closed to new replies.