maxcode / module-sitemap-exclude-cms
EN: Adds an “Exclude from XML sitemap” checkbox to the SEO tab of each Magento 2 CMS page: ticked pages are left out of the generated sitemaps. FR : Ajoute une case « Exclure du plan de site XML » dans l'onglet SEO de chaque page CMS Magento 2 : les pages cochées sont retirées des plans de site géné
Package info
github.com/eBusiness360/module-sitemap-exclude-cms
Type:magento2-module
pkg:composer/maxcode/module-sitemap-exclude-cms
Requires
- php: >=8.2
- magento/framework: ^103.0
- magento/module-cms: *
- magento/module-sitemap: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
English · Français
Maxcode Sitemap Exclude CMS for Magento 2
One switch on each CMS page to keep it out of your XML sitemap. Free, no core override, nothing to configure.
The problem
Magento's XML sitemap lists every active CMS page. The only ones it leaves out are three "utility" pages: the home page, the 404 page and the "cookies disabled" page.
Everything else ends up in the sitemap you hand to Google: the "account not approved" page of a third-party module, confirmation pages, internal pages, test pages. As of Magento 2.4.8 there is no setting to remove one of them, neither in Marketing > SEO & Search > Site Map nor on the page itself.
What it does
- A switch on every CMS page, in the Search Engine Optimization section: Exclude from XML sitemap.
- Flagged pages disappear from every sitemap, in all store views, at the next generation.
- No core override: one plugin on the sitemap's CMS pages query. Magento's own rules (inactive pages, utility pages, store view assignment) are left untouched and keep following Magento upgrades.
- Safe by default: one column,
cms_page.exclude_from_sitemap, set to0. Nothing changes until you flag a page. - Translated into English and French.
- Unit tests included.
Installation
composer require maxcode/module-sitemap-exclude-cms bin/magento module:enable Maxcode_SitemapExcludeCms bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush
Why module:enable first? The module adds a column (cms_page.exclude_from_sitemap) through
Magento's declarative schema. setup:upgrade builds the schema from the modules it already knows
when it starts, and a module that Composer has just installed is not yet listed in
app/etc/config.php. Without module:enable, the first setup:upgrade only registers the module
and a second run is needed to create the column. This is how Magento loads its module list, so it
applies to any new module that ships a db_schema.xml (observed on 2.4.8-p5). Check the result with
bin/magento setup:db:status: it must answer "All modules are up to date". If app/etc/config.php
already lists the module (for instance because it is committed and deployed with it), a single
setup:upgrade is enough.
No static content to deploy: the module only adds a field to an existing admin form.
Requirements: Magento Open Source or Adobe Commerce 2.4.x, PHP 8.2 or later. Tested on Magento Open Source 2.4.8-p5 with PHP 8.3.
Usage
- Go to Content > Elements > Pages and edit a page.
- In Search Engine Optimization, set Exclude from XML sitemap to Yes, then save.
- Regenerate the sitemap: Marketing > SEO & Search > Site Map > Generate, or wait for the scheduled generation.
Good to know. The module only manages the sitemap. It does not add
noindexand does not block crawling. A page already known to Google stays in its index until you tell Google otherwise (anoindexdirective, or a removal request in Search Console).
For developers
| Piece | Role |
|---|---|
etc/db_schema.xml |
adds cms_page.exclude_from_sitemap (smallint, not null, default 0) |
view/adminhtml/ui_component/cms_page_form.xml |
the toggle, in the search_engine_optimisation fieldset |
Plugin/Sitemap/ExcludeFlaggedPages |
afterGetCollection on Magento\Sitemap\Model\ResourceModel\Cms\Page |
The plugin receives the pages Magento found eligible for a store view, asks the database which of
them are flagged (WHERE exclude_from_sitemap = 1 AND page_id IN (…), one query per store view and
per generation) and removes them. No preference, no copy of Magento code.
Modules that replace Magento's sitemap generator altogether are not covered.
To stop using the module, run bin/magento module:disable Maxcode_SitemapExcludeCms: flagged pages
come back in the sitemap at the next generation. The column is harmless and can stay in place.
Changelog
See CHANGELOG.md.
License and support
Free for any number of Magento installations that you own or operate. You receive the full source code and may adapt it to your needs; redistribution is not allowed. See LICENSE (free-module EULA).
Provided as is, without support or update commitment. For questions and paid services: ebusiness360.fr.
