Custom Sitemap (URLs dynamically created with Plugin/API)

#218342
  • Resolved Nils
    Rank Math free

    Hey there,

    I’d like to create a custom sitemap that includes various real estate details that are embedded with a shortcode on a page and pulls data dynamically via a plugin / API on this page:

    https://example.com/real-estate/details

    This page shows up on the default page sitemap: https://example.com/page-sitemap.xml

    However, all the detail pages that are pulled from the API don’t.

    e.g.
    https://example.com/real-estate/details/1
    https://example.com/real-estate/details/2
    https://example.com/real-estate/details/3

    I would like to create a custom sitemap (real estates) for those pages. I already added custom-sitemap.php in the child-theme folder with the code below and included this code in the child’s function file:

    include_once ‘sitemap-custom.php’;
    add_filter(‘rank_math/sitemap/providers’, function( $external_providers ) {
    $external_providers[‘custom’] = new RankMathSitemapProvidersCustom();
    return $external_providers;
    });

    Perhaps RankMath cannot find the links: https://example.com/real-estate/details/* ??

    <?php

    namespace RankMathSitemapProviders;

    defined( ‘ABSPATH’ ) || exit;

    class Custom implements Provider {

    public function handles_type( $type ) {
    return true;
    }

    public function get_index_links( $max_entries ) {
    return [];
    }

    public function get_sitemap_links( $type, $max_entries, $current_page ) {
    $links = [
    [ ‘loc’ => ‘https://example.com/real-estate/details/*&#8217; ],

    ];

    return $links;
    }

    }

    The map does not show up. I tried other solutions from other support tickets already – without success.

    I appreciate your help, thanks in advance!

    Cheers,

    Nils

Viewing 8 replies - 1 through 8 (of 8 total)
  • Brian
    Rank Math free

    Hello,

    Thank you for contacting Rank Math today.

    The code you on the later that is the last one should be inserted on a new file within your child theme. Am assuming this what you have done.

    If you wish them to reflect on a new custom sitemap URL you can use this code: https://rankmath.com/kb/filters-hooks-api-developer/#18-filter-to-add-external-sitemap-to-the-rank-math-sitemap

    Hope this helps. Please let us know if you have additional questions for us.
    Thank you.

    Nils
    Rank Math free

    Thanks Brian! I was able to add the external Sitemap, but failed to add the pages to it. Since the pages are added dynamically I thought I can simply use following code:

    add_filter( ‘rank_math/sitemap/{$type}/content’, function() {
    return ‘
    <urlset xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9″&gt;
    <url>
    <loc>https://example.com/real-estate/details/*</loc&gt;
    <lastmod>2020-09-14T20:34:15+00:00</lastmod>
    </url>
    </urlset>’;
    } );

    https://example.com/real-estate/details/*&#8211; does not seem to work, though.

    Thanks for your help!

    Hello,

    Thank you for your patience.

    Could you please share the exact filter you’re using so we can also check? You can add it in the sensitive data section
    Sensitive Data Section

    It is completely secure, and only our support staff has access to that section.

    Please also note that you need to replace the {$type} with either post or page depending on if you want the URL to be included in the post or page sitemap.

    Looking forward to helping you.

    Thank you.

    Nils
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Brian
    Rank Math free

    Hello,

    You can try to create a custom sitemap and add your dynamic page links to it by adding a custom-sitemap.php file to your PHP. We use the Sitemap Providers to create these custom sitemap files.

    Please follow our guide here: https://rankmath.com/kb/custom-sitemaps/

    Do let us know if you are stuck anywhere and we will gladly help.

    Thank you.

    Nils
    Rank Math free

    Thanks Brian,

    I followed the instructions:

    1. added the sitemap-custom.php to the child’s theme
    2. added the additional code to the functions file
    3. replaced the example links

    However, no sitemap shows up. What is missing?

    Nils
    Rank Math free

    And I already a custom sitemap with the first link you sent. However, whenever I click on it, it says the page cannot be found..

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Custom Sitemap (URLs dynamically created with Plugin/API)’ is closed to new replies.