• Resolved mattyfezzer

    (@mattyfezzer)


    My site has just over 300 Location categories, but the generated rtcl_location-sitemap.xml only includes about 129 URLs. There’s no /rtcl_location-sitemap2.xml, so the sitemap isn’t paginating and the remaining Location pages are missing. It looks like RTCL is overriding Yoast’s sitemap for this taxonomy but is limited. Could you confirm if this is a bug or if there’s a way to let Yoast handle the Location sitemap so all 500+ pages are included for my locations and all categories ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Muhammad Ali Akbar

    (@alireyad)

    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

    Thread Starter mattyfezzer

    (@mattyfezzer)

    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 🙂

    Plugin Support Muhammad Ali Akbar

    (@alireyad)

    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

    Thread Starter mattyfezzer

    (@mattyfezzer)

    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);
    Plugin Support Muhammad Ali Akbar

    (@alireyad)

    Thanks for sharing details.

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

The topic ‘RTCL sitemap’ is closed to new replies.