Dynamic Exclusion of Terms From Sitemaps

#1112001
  • Resolved Solve
    Rank Math free

    Hi,
    I’m using a custom taxonomy on my site some of which have their own archive page which I want to rank, but others which do not and have a 301 set up. The 301 is set up to work dynamically based on whether an ACF true/false field is set to true. I also want to be able to exclude these from both the HTML and XML sitemaps dynamically based on this ACF field. Are there any filters I can use to achieve this functionality?
    Thanks.

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

    We apologize for the issue you’re facing. To dynamically exclude terms from your sitemaps based on an ACF true/false field, you can use the filters provided by Rank Math. Here are the relevant filters you can implement:

    1. Exclude Taxonomy from Sitemap: This filter allows you to exclude specific taxonomies from the XML sitemap.

      add_filter( 'rank_math/sitemap/exclude_taxonomy', function( $exclude, $type ) {
         // Check your ACF field here
         if ( 'your_taxonomy_name' === $type && get_field('your_acf_field_name') ) {
             $exclude = true;
         }
         return $exclude;
      }, 10, 2 );
    2. Exclude Empty Terms from Sitemap: If you want to exclude terms that are empty or do not meet certain criteria, you can use this filter as well.

      add_filter( 'rank_math/sitemap/exclude_empty_terms', function( $exclude, $taxonomy_names ) {
         // Logic to check your ACF field and set $exclude accordingly
         return $exclude;
      }, 10, 2 );

    Make sure to replace 'your_taxonomy_name' and 'your_acf_field_name' with the actual names used in your setup.

    For more detailed guidance on using these filters, you can refer to the Rank Math Filters and Hooks documentation.

    If you need further assistance or a more comprehensive setup, we recommend considering our professional setup service available at Rank Math Services. This service requires a PRO subscription and ensures your plugin setup is fully correct and adheres to the latest SEO standards.

    Thank you for raising this concern! If you have any more questions or need further clarification, feel free to reply to this ticket.

    Sources:
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    How to Make Your Theme Rank Math Compatible » Rank Math

    Solve
    Rank Math free

    Hi,

    The ACF field is linked to each individual term, not the taxonomy as a whole. I need some of the terms to show in the sitemaps as normal, and only those with this acf field set to true to be removed.
    Thanks

    Hello,

    Thank you so much for getting in touch.

    Can you please share an example URL where the ACF field is set to true? Kindly also mention the name of that ACF field.

    You can control all the incoming URLs in your sitemap using this filter code:

    /**
     * Filter URL entry before it gets added to the sitemap.
     *
     * @param array  $url  Array of URL parts.
     * @param string $type URL type. Can be user, post or term.
     * @param object $object Data object for the URL.
     */
    add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
    	return $url;
    }, 10, 3 );

    Looking forward to helping you with this one.

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

The ticket ‘Dynamic Exclusion of Terms From Sitemaps’ is closed to new replies.