Custom sitemaps for links num more than max_entries but still in one index_links

#601234
  • Resolved Anonymous
    Rank Math free

    Hi,

    I created custom sitemaps following the tutorial from https://rankmath.com/kb/custom-sitemaps/, all working well but once the custom links num more than max_entries, the links are still in the default index_links.
    I want the custom sitemap like below,
    …/custom-sitemap1.xml
    …/custom-sitemap2.xml

    How could I achieve that?
    Thanks a lot.

    Regards,
    Delia

Viewing 10 replies - 1 through 10 (of 10 total)
  • Anonymous
    Rank Math free

    Hi,
    The final style likes below:

    —————————
    index_links:
    …/custom-sitemap1.xml
    links(after open custom-sitemap1.xml):
    http://www.example.com/1
    http://www.example.com/2
    http://www.example.com/3

    —————————
    index_links:
    …/custom-sitemap2.xml
    links(after open custom-sitemap2.xml):
    http://www.example.com/21
    http://www.example.com/22
    http://www.example.com/23

    Any suggestion?
    Thanks a lot.
    Regards,
    Delia

    Hello,

    Thanks for contacting us, and sorry for any inconvenience that might have been caused due to that.

    Can you please share the sitemap with us? So that we can investigate the issue further for you.

    Meanwhile, please try following the steps below to see if that works for you.

    #1. Flush the Sitemap cache by following this video screencast:
    https://i.rankmath.com/pipRDp

    #2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
    https://rankmath.com/kb/exclude-sitemaps-from-caching/

    #3. If the above steps don’t seem to work, kindly apply the following filter code to your site.

    add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
    

    Here’s how you can add a filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Anonymous
    Rank Math free

    Hi,
    Thanks for your reply.

    I have not setup whole site now and just to design the functions of the site in my local pc.

    For example, I have 10k custom urls will add to sitemap, after I followed the tutorial from https://rankmath.com/kb/custom-sitemaps/, the function is working well, but the only problem is: all 10k urls are in 1 index url (…/custom-sitemap.xml).

    What I want to split 10k urls to: 200 urls to …/custom-sitemap.xml, next 200 urls to …/custom-sitemap2.xml, … and so on.

    Any suggestion please, thanks a lot.

    Kind Regards,
    Delia

    Hello,

    I checked with the devs and they have identified this as a bug. We have logged it and will inform you once we have fixed this.

    We really appreciate your patience in the meantime.

    Don’t hesitate to get in touch in case you need our assistance with anything else.

    Anonymous
    Rank Math free

    Hi,

    Any update yet Or how long will be updated? Thanks.
    I also find there is no lastmod in function get_sitemap_links, hope the full function could working well in the future.

    Nice day,
    Regards,
    Delia

    Hello,

    Thank you for getting back to us.

    Unfortunately, we don’t have any ETA for this fix. Rest assured that we will announce it when we release an update to fix the said issue.

    You can keep an eye on our changelog to get notified when we release this improvement in an update: https://rankmath.com/changelog/

    We appreciate your time and patience on this one.

    Hello,

    Sorry for not following up quickly. Our development team discussed this issue and it looks like the fitler to add Custom sitemap is working fine. You’ll have to add pagination in the Custom Sitemap code itself.

    Following is the Custom Sitemap code with the Pagination support:

    
    <?php
    namespace RankMath\Sitemap\Providers;
    
    defined( 'ABSPATH' ) || exit;
    
    class Custom implements Provider {
    
    	public function handles_type( $type ) {
    		return 'custom' === $type;
    	}
    
    	public function get_index_links( $max_entries ) {
    		$links = $this->get_links();
    		if ( count( $links ) <= $max_entries ) {
    			return [
    				[
    					'loc'     => \RankMath\Sitemap\Router::get_base_url( 'custom-sitemap.xml' ),
    					'lastmod' => '',
    				]
    			];
    		}
    
    		$links = array_chunk( $links, $max_entries );
    		$index = [];
    		foreach ( $links as $count => $link ) {
    			$page = $count + 1;
    			$index[] = [
    				'loc'     => \RankMath\Sitemap\Router::get_base_url( "custom-sitemap$page.xml" ),
    				'lastmod' => '',
    			];
    		}
    
    		return $index;
    
    	}
    
    	public function get_sitemap_links( $type, $max_entries, $current_page ) {
    		$links = $this->get_links();
    
    		$offset      = ( $current_page - 1 ) * $max_entries;
    		$total_count = count( $links );
    		if ( $total_count > $offset ) {
    			$new_links = array_slice( $links, $offset, $max_entries );
    			return $new_links;
    		}
    		return $links;
    	}
    
    	private function get_links() {
    		return [
    			[ 'loc' => 'http://rankmath.local/test1' ],
    			[ 'loc' => 'http://rankmath.local/test2'],
    			[ 'loc' => 'http://rankmath.local/test3' ],
    			[ 'loc' => 'http://rankmath.local/test4' ],
    			[ 'loc' => 'http://rankmath.local/test5' ],
    		];
    	}
    }
    

    Basically, this code has a new function to get the links which is used in the index & sitemap_links function to add the pagination.

    Hope that helps.

    Hello,

    We released a quick Beta update you can try to see if that helps.

    Please enable the Beta update by following this:
    https://rankmath.com/kb/version-control/#beta-updates

    beta update

    If you are unable to see an update, please clear Rank Math’s transients from:
    WP Dashboard > Rank Math > Status & Tools > Database Tools > Remove Rank Math Transients > Remove transients
    remove transients rank math

    Please clear the caches, server, and WordPress after updating.

    You can disable the Beta updates once you update to the latest version and if the issue is fixed.

    We are here to assist. Thank you.

    Anonymous
    Rank Math free

    Hi,
    Thanks for your codes, I tried it and working well for pagination. I tried to add lastmod parts for single sitemap link like sitemap index parts but it is not showing lastmod with the below format:

    private function get_links() {
    return [
    [ ‘loc’ => ‘http://rankmath.local/test1&#8242;,’lastmod’ => ‘2023-07-31 08:27 +00:00’ ],
    [ ‘loc’ => ‘http://rankmath.local/test2&#8242;,’lastmod’ => ‘2023-07-31 08:27 +00:00’],
    [ ‘loc’ => ‘http://rankmath.local/test3&#8242;,’lastmod’ => ‘2023-07-31 08:27 +00:00’ ],
    [ ‘loc’ => ‘http://rankmath.local/test4&#8242;,’lastmod’ => ‘2023-07-31 08:27 +00:00’ ],
    [ ‘loc’ => ‘http://rankmath.local/test5&#8242;,’lastmod’ => ‘2023-07-31 08:27 +00:00’ ],
    ];
    }

    Anything wrong with the single links format?
    Kind Regards,
    Delia

    Hello,

    Instead of lastmod, please add the date in the mod. Here is the updated code:

    
    <?php
    namespace RankMath\Sitemap\Providers;
    
    defined( 'ABSPATH' ) || exit;
    
    class Custom implements Provider {
    
    	public function handles_type( $type ) {
    		return 'custom' === $type;
    	}
    
    	public function get_index_links( $max_entries ) {
    		$links = $this->get_links();
    		if ( count( $links ) <= $max_entries ) {
    			return [
    				[
    					'loc'     => \RankMath\Sitemap\Router::get_base_url( 'custom-sitemap.xml' ),
    					'lastmod' => '2023-07-31 08:27 +00:00',
    				]
    			];
    		}
    
    		$links = array_chunk( $links, $max_entries );
    		$index = [];
    		foreach ( $links as $count => $link ) {
    			$page = $count + 1;
    			$index[] = [
    				'loc'     => \RankMath\Sitemap\Router::get_base_url( "custom-sitemap$page.xml" ),
    				'lastmod' => $link[ $count ]['mod'],
    			];
    		}
    
    		return $index;
    
    	}
    
    	public function get_sitemap_links( $type, $max_entries, $current_page ) {
    		$links = $this->get_links();
    
    		$offset      = ( $current_page - 1 ) * $max_entries;
    		$total_count = count( $links );
    		if ( $total_count > $offset ) {
    			$new_links = array_slice( $links, $offset, $max_entries );
    			return $new_links;
    		}
    		
    
    		return $links;
    	}
    
    	private function get_links() {
    		return [
    			[ 'loc' => 'http://rankmath.local/test1&#8242', 'mod' => '2023-07-31 08:27 +00:00' ],
    			[ 'loc' => 'http://rankmath.local/test2&#8242', 'mod' => '2023-07-29 08:27 +00:00'],
    			[ 'loc' => 'http://rankmath.local/test3&#8242', 'mod' => '2023-07-31 08:27 +00:00' ],
    			[ 'loc' => 'http://rankmath.local/test4&#8242', 'mod' => '2023-07-31 08:27 +00:00' ],
    			[ 'loc' => 'http://rankmath.local/test5&#8242', 'mod' => '2023-07-31 08:27 +00:00' ],
    		];
    	}
    }
    

    Hope that helps.

    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 10 replies - 1 through 10 (of 10 total)

The ticket ‘Custom sitemaps for links num more than max_entries but still in one index_links’ is closed to new replies.