Hi,
We don’t have sitemap for Categories and Location in plugin core features and we did not override it for Yoast. We have sitemap for Listings data only. May be there have limitation or hook to generate all. You can check there documentation. How did you generate it for Yoast? Do you need only location sitemap?
Thank you
Thank you for getting back to me, I generated my own sitemap in the end to include all categories and locations, I think its because some categories and locations have no content, I was able to include them all and force google to index 🙂
Hi,
Thanks for the update! Yes, that could be the reason. Could you mention how to force it to include all items? That way others who run into the same issue will find it useful too.
Thank you
Sure I used a snippet that forces all RTCL into sitemap in Yeost, anyone can use this snippet and then clear cache and open sitemap and should see all listed then upload to google console
<?php
/**
* RTCL Taxonomy Sitemap (REST API)
* Provides a read-only sitemap of RTCL Locations & Categories
* and automatically adds it to Yoast's sitemap index.
*
* URL: /wp-json/rtcl/v1/sitemap
*/
if (!defined('ABSPATH')) exit;
/**
* REST: /wp-json/rtcl/v1/sitemap
*/
add_action('rest_api_init', function () {
register_rest_route('rtcl/v1', '/sitemap', [
'methods' => 'GET',
'callback' => function () {
// Use a transient cache to prevent DB overload
$cached = get_transient('rtcl_rest_sitemap_xml');
if ($cached !== false) {
nocache_headers();
header('Content-Type: application/xml; charset=' . get_bloginfo('charset'), true);
header('Cache-Control: public, max-age=3600');
echo $cached;
return null;
}
// Get public taxonomies only, skip empty terms
$terms = get_terms([
'taxonomy' => ['rtcl_location', 'rtcl_category'],
'hide_empty' => true,
'number' => 0,
'update_term_meta_cache' => false,
]);
if (is_wp_error($terms)) $terms = [];
$charset = get_bloginfo('charset');
$lastmod = gmdate('c');
// Build XML
$xml = '<?xml version="1.0" encoding="' . esc_attr($charset) . "\"?>\n";
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
foreach ($terms as $term) {
$loc = get_term_link($term);
if (is_wp_error($loc)) continue;
$xml .= " <url>\n";
$xml .= ' <loc>' . esc_url($loc) . "</loc>\n";
$xml .= ' <lastmod>' . $lastmod . "</lastmod>\n";
$xml .= " </url>\n";
}
$xml .= "</urlset>";
// Cache XML for 1 hour
set_transient('rtcl_rest_sitemap_xml', $xml, HOUR_IN_SECONDS);
// Output XML
nocache_headers();
header('Content-Type: application/xml; charset=' . $charset, true);
header('Cache-Control: public, max-age=3600');
echo $xml;
return null;
},
'permission_callback' => '__return_true', // Public read-only access
]);
});
/**
* Add this sitemap to Yoast's sitemap index
*/
add_filter('wpseo_sitemap_index_links', function ($links) {
$links[] = [
'loc' => home_url('/wp-json/rtcl/v1/sitemap'),
'lastmod' => gmdate('c'),
];
return $links;
});
/**
* Optional: redirect /sitemap-rtcl.xml to REST URL
*/
add_action('template_redirect', function () {
$path = isset($_SERVER['REQUEST_URI']) ? parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) : '';
if ($path && rtrim($path, '/') === '/sitemap-rtcl.xml') {
wp_redirect(home_url('/wp-json/rtcl/v1/sitemap'), 301);
exit;
}
});
/**
* Optional: add sitemap to robots.txt
*/
add_filter('robots_txt', function ($output, $public) {
$output .= "\nSitemap: " . home_url('/wp-json/rtcl/v1/sitemap');
return $output;
}, 10, 2);
Thanks for sharing details.