Remove empty post from sitemap

#71042
  • Resolved Joe
    Rank Math free

    How can I remove posts that have no content from sitemap? I tried some filters but couldn`t make it work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Joe
    Rank Math free

    Okay I solved it, will put the code if anyone ever needs it 🙂

    add_filter( ‘rank_math/sitemap/posts_to_exclude’, function( $posts_to_exclude ){
    $posts_ids = [];
    $posts = get_posts();
    foreach ($posts as $post) {
    if($post->post_content == “”) {
    $posts_ids [] = $post->ID;
    }
    }
    return array_merge( $posts_to_exclude,$posts_ids );
    });

    Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math today.

    Thank you for sharing it, I am sure it will be really useful for a lot of users. If you have any other questions or issues, we are here to help you.

    Looking forward to helping you. Thank you.

    ​​​​​​

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this ticket.