Answer the question
In order to leave comments, you need to log in
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);
}
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://immobiliareclass.com/sitemap.xml
add_filter('wp_sitemaps_enabled', '__return_false');
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question