Incorrect header::contentType on sitemap


I’ve been putting together a small test site to play with Kirby 3. As part of this I wanted to generate an automatic sitemap so I followed the instructions here:

I think I’ve followed everything correctly, however when I run a validation check on the sitemap using the xml-sitemap’s checker I get an error of:

Incorrect http header content-type: “text/html; charset=UTF-8” (expected: “application/xml”)

To check what I’ve done, I have a snippet in site/snippets called sitemap.php:

<?= '<?xml version="1.0" encoding="utf-8"?>'; ?>
<urlset xmlns="">
    <?php foreach ($pages as $p): ?>
        <?php if (in_array($p->uri(), $ignore)) continue ?>
            <loc><?= html($p->url()) ?></loc>
            <lastmod><?= $p->modified('c') ?></lastmod>
            <priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>
    <?php endforeach ?>

and in site/config/config.php I have:

'sitemap.ignore' => ['error'],
'routes' => [
'pattern' => 'sitemap.xml',
'action'  => function() {
    $pages = site()->pages()->index();

    // fetch the pages to ignore from the config settings,
    // if nothing is set, we ignore the error page
    $ignore = kirby()->option('sitemap.ignore', 'error');

    // set the correct header type
    header::contentType('text/xml', 'UTF-8', true);

    return snippet('sitemap', compact('pages', 'ignore'), true);
'pattern' => 'sitemap',
'action'  => function() {
  return go('sitemap.xml', 301);

and the HTML generated is:

<?xml version="1.0" encoding="utf-8"?><urlset xmlns="">
            <loc>*website url*</loc>

The generated HTML looks correct, so I think the problem is the header::contentType isn’t being set correctly by the config file.

Can anyone help me see where I’m going wrong?

you need to use a new way to send headers in kirby3.

also a plugin exists for sitemaps if you need a ready-to-use solution.


The instruction I’m using to set the header content type is the same as in the cookbook article on sitemaps which I would have thought would be right? I’ll have a look at the forum post you linked to and try that.


i see. as far i know her @texnixe has read this already, she will check the cookbook example and fix it if needed.