Alt Sitemap is a Statamic addon for creating sitemaps to help search engines discover URLs on your site
Features
- Create basic sitemaps detailing
- Set priority of entire collections/taxonomies
- Set priority of specific entries/terms
- Exclude certain entries/terms from the sitemap.
- Exclude entire collections/taxonomies from the sitemap.
- Split large sitemaps into an index of per-collection/taxonomy child sitemaps.
Requirements
- PHP 8.1+ (PHP 8.3+ when using Statamic 6)
- Statamic 4.x, 5.x, or 6.x
How to Install
You can search for this addon in the Tools > Addons section of the Statamic control panel and click install, or run the following command from your project root:
composer require alt-design/alt-sitemap
How to Use
After installation, access your sitemap at /sitemap.xml
Only entries/terms with a public URL are listed. A collection (or taxonomy) with no Route configured produces no URLs, so its entries will never appear in the sitemap — split or not. Set a route in CP > Collections > your collection > Configure Collection > Routing & URLs.
- Set priorities for entire collections/taxonomies in CP > Alt Tools > SEO > Alt Sitemap.
- Exclude entire collections/taxonomies in CP > Alt Tools > SEO > Alt Sitemap.
- Set entry/term priorities in the entry/term under the Alt Sitemap tab. Entry priorities will override collection/taxonomy priorities.
- Priorities are set as 0.5 by default.
- Exclude entries/terms from the sitemap in the entry under the Alt Sitemap tab.
Splitting the Sitemap
Very large sitemaps can be broken up so crawlers index them more reliably. Enable Split into child sitemaps in CP > Alt Tools > SEO > Alt Sitemap. When enabled, /sitemap.xml becomes a sitemap index that links to smaller child sitemaps, each named by handle:
/sitemap-products.xml/sitemap-blog.xml/sitemap-brands.xml...
Choose which collections/taxonomies get their own child sitemap with Collections/Taxonomies with their own sitemap. Anything you don't select (and manually registered items) is bundled into a single /sitemap-other.xml. Leave both pickers empty to split every collection and taxonomy by its handle.
Priorities and exclusions still apply throughout.
Where the settings are stored
On Statamic 6 the sitewide settings are Statamic addon settings, so they live wherever the site keeps those:
resources/addons/alt-sitemap.yamlby default. Commit this file. On a zero-downtime deployment the folder is part of each release, so a change saved in the control panel on the server is lost at the next deploy unless it is committed or the folder is shared between releases.- The
addon_settingstable when statamic/eloquent-driver hasaddon_settings.driverset toeloquent.
On Statamic 4 and 5 they stay in content/alt-sitemap/settings.yaml, as before.
Updating a Statamic 6 site from 1.6 or earlier
Nothing has to be done for the site to keep working: until the site has addon settings of its own, the addon reads the old content/alt-sitemap/settings.yaml.
composer update alt-design/alt-sitemapcopiescontent/alt-sitemap/settings.yamltoresources/addons/alt-sitemap.yaml. Commit the new file. The old file is left where it is and can be deleted once you are happy. (composer installdoes not run the copy; saving the settings once in the control panel does the same job.)- If the site keeps addon settings in the database, deploy and run
php please eloquent:import-addon-settingsonce. It replaces what is in the database with what is inresources/addons, so do not run it again after settings have been changed in the control panel.
Manual Entries
Add a single, or multiple items to the sitemap, using code similar to the following in a service provider's boot() (e.g. AppServiceProvider) method.
Using registerItem() to register a single item.
$this->callAfterResolving( AltSitemapController::class, function ($altSitemapController) { $altSitemapController->registerItem( [ '/url-1', ] ); });
Using registerItems() to register multiple items at once.
$this->callAfterResolving( AltSitemapController::class, function ($altSitemapController) { $altSitemapController->registerItems( [ [ '/url-1', ], [ '/url-2', Carbon::create(2024,10,23,12,20,0, 'UTC'), ], [ '/url-3', Carbon::create(2024,10,23,12,20,0, 'UTC'), 0.8 ], ] ); } );
Questions etc
Drop us a big shout-out if you have any questions, comments, or concerns. We're always looking to improve our addons, so if you have any feature requests, we'd love to hear them.
Starter Kits
Addons
- Alt Redirect Addon
- Alt Sitemap Addon
- Alt Akismet Addon
- Alt Password Protect Addon
- Alt Cookies Addon
- Alt Inbound Addon
- Alt Google 2FA Addon
Postcardware
Send us a postcard from your hometown if you like this addon. We love getting mail from other cool peeps!
Alt Design
St Helens House
Derby
DE1 3EE
UK