-
Hey Team,
Followed this > https://rankmath.com/kb/custom-sitemaps/
And have it working with my dynamic data which lists out all the indexable URL’s.
However, I cannot control the lastmod value?
I have stripped back my code to that of the docs above and still cannot get the last mode dates to propagate in the site map?
namespace RankMath\Sitemap\Providers;defined( 'ABSPATH' ) || exit;
class Custom implements Provider {
public function handles_type( $type ) {
return 'properties' === $type;
}public function get_index_links( $max_entries ) {
return [
[
'loc' => \RankMath\Sitemap\Router::get_base_url( 'properties-sitemap.xml' ),
'lastmod' => '',
]
];
}public function get_sitemap_links( $type, $max_entries, $current_page ) {
$links = [
[
'loc' => 'http://www.example.com/',
'lastmod' => '2023-01-01',
'images' => [
[
'src' => 'http://www.example.com/image1.png',
'title' => 'Image Title',
],
[
'src' => 'http://www.example.com/image2.png',
'title' => 'Image 2 Title',
],
],
],
[
'loc' => 'http://www.example.com/2',
'lastmod' => '2023-09-27 22:00 +00:00' // Testing with current rankmath lastmod string
],
];return $links;
}
}
See image of the site map generated:
I have tried this on a fresh install with just Rankmath and still same issue.
I am clearing the cache so this is not the issue. I have also found that the code below within functions.php can create blocking issues (running other php scripts directly) which results in a critical error when this code is present – no errors in logs or in wp_debug mode
// Add generated property URLs into Rank Maths site map index
include_once( get_stylesheet_directory() . '/php/properties-sitemap.php');
add_filter('rank_math/sitemap/providers', function( $external_providers ) {
$external_providers['custom'] = new \RankMath\Sitemap\Providers\Custom();
return $external_providers;
});add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
Let me know if you need any extra info
The ticket ‘Create a Custom Sitemap with custom lastmod params’ is closed to new replies.