I found where the issue is coming from in my theme’s functions.php file i have added on filter to change the backend URL to the frontend URL because I have a headless WordPress website, if i comment below code and then check then all my sitemap pages working fine, so is there any solution for this ?
function custom_frontend_post_link($permalink, $post, $leavename) {
if ($post->post_type === 'post') {
// Your frontend base URLx
$frontend_base_url = 'https://frontend-site.com';
$frontend_url = $frontend_base_url . '/' . $post->post_name;
return $frontend_url;
}
// Return the default permalink for other post types
return $permalink;
}
add_filter('post_link', 'custom_frontend_post_link', 10, 3);
Hello,
Thank you for contacting support.
Those changes happen before the sitemap generation so it prevents the sitemap from generating the data because it can’t match the data to what it sees in the database settings.
You would need to implement a different solution where that filter is not applied to the WordPress installation.
Don’t hesitate to get in touch if you have any other questions.
So could you please suggest what other solution should i try ?
Hello,
Unfortunately, this type of customization falls outside the scope of our support.
We can suggest excluding the sitemap path in your filter code like so:
function custom_frontend_post_link($permalink, $post, $leavename) {
if ($post->post_type === 'post' && strpos($permalink, 'sitemap') === false) {
$frontend_base_url = 'https://frontend-site.com';
$frontend_url = $frontend_base_url . '/' . $post->post_name;
return $frontend_url;
}
return $permalink;
}
add_filter('post_link', 'custom_frontend_post_link', 10, 3);
However, we haven’t tested this code on our end so if this doesn’t work, we suggest hiring a coder to customize the code for you.
Hope that helps.
Thank 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.