Skip to content

datenliebe/kirby-sitemap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kirby sitemap.xml Plugin

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.

Features

  • 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.

Installation

  1. Clone or download this repository into your site/plugins directory:

    git clone https://github.com/datenliebe/kirby-sitemap.git site/plugins/sitemap
  2. The plugin is now installed and ready to use.


Usage

Default Behavior

By default, the plugin generates a sitemap.xml file that includes all listed pages except those specified in the default ignore list:

  • error

Customizing Ignore Pages

To exclude additional pages from the sitemap, define them in your config.php using the datenliebe.sitemap.ignore option.

Example Config

return [
    'datenliebe.sitemap.ignore' => [
        'secret-page',
        'another-hidden-page',
    ],
    'datenliebe.sitemap.includeUnlisted' => false, // Exclude unlisted pages
];

Example Output

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.


Multilingual 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.

Example Output for Multilingual Sites

<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>

Sitemap Priority

Pages are included in the sitemap based on the following priority:

  1. All listed pages (published and visible).
  2. Additional unlisted pages (if includeUnlisted is set to true).
  3. Pages explicitly ignored via the default or custom ignore lists.

Providing the Snippet with the Plugin

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.

Plugin Structure

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.


Example sitemap.xml

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>

Options

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

License

This plugin is licensed under the MIT License.


Contributing

Feel free to submit issues or pull requests to improve this plugin. Contributions are always welcome!


Questions?

If you have any questions or need assistance, feel free to reach out or create an issue in the repository.

About

A sitemap.xml generator for Kirby CMS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages