• Resolved rstrah

    (@rstrah)


    add_filter('rank_math/sitemap/exclude_post', function($exclude, $post) {
    2
    3 $excluded_urls = [
    4 'https://site.com/blog/',
    5 'https://site.com/case_studies/',
    6 'https://site.com/services/',
    7 'https://site.com/solutions/'
    8 ];
    9
    10
    11 $post_url = get_permalink($post->ID);
    12
    13
    14 if (in_array($post_url, $excluded_urls)) {
    15 return true;
    16 }
    17
    18 return $exclude; // Возвращаем оригинальное значение
    19}, 10, 2);

    These are the most important taxonomy pages that are created at once by wp. How can they be excluded from sitemap?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @rstrah,

    Thank you for contacting Rank Math support.

    Please use the following filter to exclude the URLs from the sitemap:


    add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
    $excluded_urls = [
    'https://site.com/blog/',
    'https://site.com/case_studies/',
    'https://site.com/services/',
    'https://site.com/solutions/'
    ];
    $post_url = get_permalink($object->ID);
    if ($type === 'post') {
    if (in_array($post_url, $excluded_urls)) {
    return '';
    }
    }
    return $url;
    }, 10, 3 );

    Please make sure to flush the Sitemap cache by following this video screencast after adding the filter: https://i.rankmath.com/pipRDp

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

    Thread Starter rstrah

    (@rstrah)

    @rankmathsupport
    https://prnt.sc/K3JeW8j28D0K
    https://prnt.sc/qhIfGUCSwCjw
    not working

    • This reply was modified 1 week, 3 days ago by rstrah.
    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @rstrah,

    Please confirm if you want to exclude the URLs from the page sitemap. If so, the filter should work fine. Please make sure to clear sitemap cache. If you want to remove the URLs from their specific post type sitemaps, you should use the following filter:

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

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.