The datenliebe/kirby-sitemap plugin for Kirby CMS simplifies the generation of a dynamic sitemap.xml
file. It allows you to define default ignored pages, extend the list with custom pages via config.php
, and dynamically serve the combined sitemap.
- Plug & Play: Installing the plugin in your
site/plugins
directory generates a basic sitemap.xml automatically — no configuration needed. - Default Ignore Pages: Automatically excludes commonly ignored pages like:
error
- Custom Ignore Pages via Config: Extend the ignore list in
config.php
. - Dynamic Sitemap: Generates and serves a combined sitemap dynamically at
/sitemap.xml
. - Multilingual Support: Handles multilingual sites by including alternate language URLs.
-
Clone or download this repository into your
site/plugins
directory:git clone https://github.com/datenliebe/kirby-sitemap.git site/plugins/sitemap
-
The plugin is now installed and ready to use.
By default, the plugin generates a sitemap.xml
file that includes all listed pages except those specified in the default ignore list:
error
To exclude additional pages from the sitemap, define them in your config.php
using the datenliebe.sitemap.ignore
option.
return [
'datenliebe.sitemap.ignore' => [
'secret-page',
'another-hidden-page',
],
'datenliebe.sitemap.includeUnlisted' => false, // Exclude unlisted pages
];
With the above configuration, your sitemap will exclude the following pages:
error
secret-page
another-hidden-page
If includeUnlisted
is set to true
, unlisted (published) pages will also be included in the sitemap.
For multilingual sites, the plugin automatically includes alternate language URLs in the sitemap. Each page entry will have a <xhtml:link>
tag pointing to its translations.
<url>
<loc>https://example.com/en/page</loc>
<lastmod>2024-12-31</lastmod>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/page" />
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/page" />
</url>
Pages are included in the sitemap based on the following priority:
- All listed pages (published and visible).
- Additional unlisted pages (if
includeUnlisted
is set totrue
). - Pages explicitly ignored via the default or custom ignore lists.
The sitemap XML generation logic is implemented in a snippet included with the plugin. This ensures the plugin is fully self-contained and easy to use without requiring manual snippet creation.
The plugin includes the snippet in its directory structure:
site/plugins/sitemap/
├── index.php
├── snippets/
│ └── sitemap.php
The sitemap.php
snippet is registered with the plugin and is automatically used to generate the sitemap content.
With custom ignore pages and multilingual support, the generated sitemap.xml
might look like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/page</loc>
<lastmod>2024-12-31</lastmod>
</url>
<url>
<loc>https://example.com/en/page</loc>
<lastmod>2024-12-31</lastmod>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/page" />
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/page" />
</url>
</urlset>
The following options can be set in your config.php
:
Option | Description | Default |
---|---|---|
datenliebe.sitemap.ignore |
Array of page IDs to ignore in the sitemap | [] |
datenliebe.sitemap.includeUnlisted |
Include unlisted (draft) pages in the sitemap | false |
This plugin is licensed under the MIT License.
Feel free to submit issues or pull requests to improve this plugin. Contributions are always welcome!
If you have any questions or need assistance, feel free to reach out or create an issue in the repository.