S
S
Sergey Burduzha2021-09-09 10:12:42
WordPress
Sergey Burduzha, 2021-09-09 10:12:42

How to disable wp-sitemap.xml in wordpress?

Good afternoon.
I'm getting posts on the site from another site and I need to add them to the sitemap.

To display these posts, I created an ads page, and as a get parameter I get the post id and already display it on the page.

https://immobiliareclass.com/ads/?id=546815

To create a sitemap, I found such a script.

add_action("save_post", "eg_create_sitemap");
function eg_create_sitemap()
{
    $postsForSitemap = get_posts(array(
        'numberposts' => -1,
        'orderby'     => 'modified',
        'post_type'   => array('post', 'page'),
        'order'       => 'DESC'
    ));

    $adsForSitemap = getPropertiesId();

    $sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
    $sitemap .= "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    foreach ($postsForSitemap as $post) {
        setup_postdata($post);
        $postdate = explode(" ", $post->post_modified);
        $sitemap .= "\t" . '<url>' . "\n" .
            "\t\t" . '<loc>' . get_permalink($post->ID) . '</loc>' .
            "\n\t\t" . '<lastmod>' . $postdate[0] . '</lastmod>' .
            "\n\t\t" . '<changefreq>monthly</changefreq>' .
            "\n\t" . '</url>' . "\n";
    }
    foreach ($adsForSitemap as $item) {
        setup_postdata($post);
        $sitemap .= "\t" . '<url>' . "\n" .
            "\t\t" . '<loc>https://immobiliareclass.com/ads?id=' . $item->id . '</loc>' .
            "\n\t\t" . '<lastmod>' . $item->updated_at . '</lastmod>' .
            "\n\t\t" . '<changefreq>monthly</changefreq>' .
            "\n\t" . '</url>' . "\n";
    }
    $sitemap .= '</urlset>';
    $fp = fopen(ABSPATH . "sitemap.xml", 'w');
    fwrite($fp, $sitemap);
    fclose($fp);
}


I tried this script on another site and it works there. And on this there is a problem with wp-sitemap.xml.
If I write url/sitemap.xml in the browser, then it redirects to url/wp-sitemap.xml

https://immobiliareclass.com/robots.txt

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: https://immobiliareclass.com/sitemap.xml


I found a script that disables wp-sitemap

add_filter('wp_sitemaps_enabled', '__return_false');


Only this filter disables not only wp-sitemap but also sitemap.xml

Thanks in advance for your reply.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Burduzha, 2021-09-09
@serii81

Issue resolved.
Trite, I forgot to include the sitemap.php file in functions.php.
I just had to make a map for several sites, and some worked.
Also, I use rankmath for seo, and the sitemap was disabled for the plugin.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question