- PHP 74.7%
- JavaScript 25.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| admin-next | ||
| blueprints | ||
| classes | ||
| docs/images | ||
| languages | ||
| tests | ||
| .gitignore | ||
| blueprints.yaml | ||
| CHANGELOG.md | ||
| composer.json | ||
| LICENSE | ||
| phpstan.neon.dist | ||
| README.md | ||
| seo-manager.php | ||
| seo-manager.yaml | ||
SEO Manager
A Grav 2.0 plugin that gives pages, Route Map GPS routes and
Subfolder Gallery galleries proper SEO: titles, meta
descriptions, Open Graph/Twitter cards, robots control, schema.org JSON-LD
(including ImageGallery for galleries and TouristTrip for routes), and a
live XML sitemap.
Everything is configured from Admin2. There is no public-facing settings form of any kind — global defaults live on the plugin's own Settings page, per-page overrides live on a new SEO tab on every page, and a SEO Manager page in the sidebar handles bulk edits and site-wide health reporting. The plugin only reads that configuration to decide what to render on the live site.
Install
git clone forgejo@code.hall.me.uk:david/seo-manager.git user/plugins/seo-manager
Or drop the seo-manager folder into user/plugins/ so you end up with
user/plugins/seo-manager/seo-manager.php, then clear the cache:
bin/grav clear-cache
This is a manual install — like Route Map and Subfolder Gallery elsewhere in
this install, there's no Composer step and no vendor/ folder.
Requires the API plugin (and therefore Admin2) to manage settings. Without it the plugin still works — front-end rendering and the sitemap don't depend on the API plugin at all — but global settings, the page SEO tab's editor experience, the SEO Manager page and the editor panel are all delivered through it.
What you get
Global settings — Admin2 → Plugins → SEO Manager
- General — site name, title template (
{title} {sep} {sitename}, with a separate template for the home page), default description, default social image, robots defaults, canonical URL handling. - Social — Open Graph type, locale, Twitter card defaults, Twitter/Facebook handles, and an Organization entity for JSON-LD.
- Structured Data — master switch, WebSite/Breadcrumb toggles, the default schema.org type, and per-template overrides. Gallery and Route Map pages get their own default types automatically.
- Sitemap — route, default priority/change-frequency, excluded templates/routes, and whether to include the Google image-sitemap extension.
- Advanced — search-console verification codes, whether the page SEO
tab is injected (and which templates it's limited to), and extra
sitewide
<meta>tags.
Per-page settings — the "SEO" tab
Every page gets an SEO tab (turn this off, or limit it to specific templates, under Advanced settings) with:
- SEO title and meta description, each with a live character counter against the length search engines typically show.
- Focus keyword (for your own reference — shown in the SEO Manager and the editor panel).
- Canonical URL override,
robotscontrols (noindex/nofollow/noarchive/ noimageindex), a structured-data type override. - Open Graph and Twitter overrides (title/description/image/type/card).
- Sitemap controls (exclude, priority, change frequency).
- Page-specific extra
<meta>tags.
Every field falls back sensibly when left blank: SEO title → page title, description → site default → an automatic summary of the page content, image → the page's first image → the site default image.
The automatic summary uses only text a reader sees. Text inside <script>,
<style>, <noscript> and <template>, and anything marked
aria-hidden="true", is left out, so another plugin's data block or fallback
message (Route Map's "The map needs JavaScript", say) never ends up in a meta
description. Paragraphs and list items are kept apart by a space, and when
the page summary comes out at a sentence or less (a post that opens with a
gallery or a map) the page's full text is used instead, unless you've marked
your own summary with Grav's === delimiter.
Images in og:image, twitter:image, structured data and the image sitemap
are always full addresses (https://your-site/...), which Facebook, X and
Google require.
Grav's API plugin (1.1.10, which Admin2 uploads through) saves uploaded files readable by their owner only. On hosts that serve files as a different user from PHP (cPanel), Facebook, X and Google would then get 403 Forbidden for the default social image and the organisation logo, so SEO Manager makes those two readable by everyone the first time a page uses them.
SEO Manager — bulk editing
A dedicated sidebar page lists every routable page with its resolved SEO status (not just what's been typed in — what will actually render), with search, template and issue filters. Select any number of pages and:
- Turn noindex/nofollow on or off
- Exclude from the sitemap, or set a priority/change frequency
- Fill in a missing SEO title from a template
- Auto-generate a missing meta description from page content
- Clear all SEO overrides
A health summary at the top flags missing descriptions, pages with no SEO title set, noindexed pages, pages with no social image, and — importantly — duplicate titles and descriptions across the site, which is one of the most common real-world SEO problems and easy to miss page-by-page.
In-editor SEO panel
While editing a page, open the SEO panel from the editor toolbar for a live Google-style search-result preview and a pass/fail checklist (title and description length, social image present, canonical resolved, indexability). Save the page and refresh the panel to see the effect.
The live site
<title>, meta description/robots, canonical link, Open Graph and Twitter tags, and JSON-LD are all rewritten into the final rendered HTML on every request (onOutputGenerated) — this works with any theme, including the one already installed on this site, without editing a single template file.- Robots restrictions already in the page are kept: if the theme, another
plugin or the page's own
metadata: robotsasks fornoindex(ornofollow,noarchive,noimageindex,nosnippet,none), that stays in the robots tag even when the SEO tab says otherwise. The stricter setting always wins. - Error pages (404 and other 4xx/5xx responses) are marked
noindex, with no canonical link and no structured data. /sitemap.xml(route configurable) is generated live from the current pages collection — no separate cache to fall out of sync, no cron job. It only lists pages a visitor without an account can read: pages withaccess:rules,login.visibility_requires_accessor Page Password, everything under them, and anything the Login plugin says a guest can't see are left out.- Gallery pages get an
ImageGalleryJSON-LD entity with every detected gallery image. Route Map pages get aTouristTripentity with anitinerarybuilt from the page's route names.
Turn front-end rendering off entirely (Advanced → "Render <head> tags on
the live site") if you'd rather use this plugin purely as an Admin2 editing
surface for SEO data and render it yourself.
How gallery/route detection works
-
Subfolder Gallery: SEO Manager asks for a page's gallery photos with the
onSeoManagerGalleryImagesevent. Subfolder Gallery 2.1 and later answer with every photo in the page's gallery folders, each with the date it was taken and the photographer, copyright line and licence pages from its settings. These go into each photo'sImageObjectin the structured data (creator,creditText,copyrightNotice,license,acquireLicensePage,dateCreated), which Google can show with the photo in image search. The photo's location is never included. For a protected page the answer is an empty list. With an older Subfolder Gallery, or none, SEO Manager scans thegallery_slotsfolders itself and lists just the photos' addresses.The image sitemap lists only each photo's address: Google stopped reading the sitemap's caption, title and licence tags in 2022, so the details go in the structured data instead.
Another plugin can answer the event too: set
$event['images']to a list of arrays with aurland any of the keys above (creatoris a name). -
Route Map: detected from
header.route_map.routes, the field that plugin writes when GPS tracks are uploaded.
Both are best-effort and loosely coupled on purpose: if either plugin is absent or a page simply has no gallery/routes, detection just returns nothing and the page gets the normal default schema type.
Known limitations
- Per-image alt text isn't managed here — that's Grav core's own page media metadata (Admin2's Media panel), and out of scope for this plugin's first version.
- Head rewriting parses and re-serializes only the page's
<head>on every request; everything else is sent exactly as the theme wrote it. (Writing a whole page back out after parsing it can change what it means: text escaped inside an attribute in a<noscript>comes back as live markup.) On PHP 8.4 and later this uses PHP's HTML5 parser, so the head comes out the way a browser would read it. On PHP 8.3 it falls back to libxml's older HTML parser, whose output depends on the libxml version installed. - A page whose
<head>holds something that belongs in the body (a<div>, say) is left without SEO Manager's tags, rather than have what follows it moved or lost. - A built sitemap is kept in Grav's cache for an hour by default
(
sitemap.cache_lifetime; 0 builds it on every request). It is rebuilt as soon as any page, the site config or the language changes, after the same few seconds Grav itself takes to notice a changed page, and when a page reaches itspublish_dateorunpublish_date. With Grav's cache switched off, it is built on every request. - Redirect management (301s for moved/renamed pages) isn't included — out of scope for this version.
Tests
The tests and PHPStan both need Grav's own classes, so they load a
Grav 2 install through Grav's tests/phpstan/plugins-bootstrap.php:
composer install
composer test
composer phpstan
If the plugin folder sits in, or is symlinked into, a site's user/plugins, that site is
found by itself; otherwise say where it is with GRAV_ROOT=/var/www/grav composer test.
Nothing on the site is read or changed: pages are stubs built from Grav's PageInterface,
and config changes only last for the test run.
The tests cover the <head> rewrite (JSON-LD escaping, robots merging, canonical and
title handling, that everything outside the head comes back byte for byte), the resolver (title templates,
descriptions, robots from every source, error pages, canonical rules), which pages count
as public, including asking the Login plugin through its real handler, and which pages the
sitemap lists. The <head> tests run against both the HTML5 parser and the libxml
fallback. PHPStan runs at level 8 with the settings in phpstan.neon.dist, which follow
the ones Grav ships for plugins, but on PHPStan 2: Grav's 1.x predates PHP 8.4's Dom\
classes. Composer and its vendor/ folder are only for
these; the plugin itself has no Composer dependencies.
How it hangs together
| File | Job |
|---|---|
seo-manager.php |
Event wiring: blueprint injection, API routes, sidebar/panel registration, sitemap route, head rendering |
classes/Resolver.php |
Computes the effective SEO data for a page (overrides → site defaults → computed fallbacks) — the single source of truth every other part of the plugin uses |
classes/JsonLd.php |
Builds the schema.org @graph (Organization, WebSite, BreadcrumbList, main entity) |
classes/HeadInjector.php |
Rewrites <head> in the final rendered HTML |
classes/Sitemap.php |
Builds sitemap.xml |
classes/PublicAccess.php |
Decides which pages are open to guests, for the sitemap |
classes/Api/SeoApiController.php |
Admin2-facing API: page list/detail/update, bulk actions, site health |
blueprints/seo-tab.yaml |
The per-page "SEO" tab, merged into every page blueprint |
admin-next/fields/seo-counter.js |
Character-counter field used by the SEO title/description fields |
admin-next/pages/seo-manager.js |
The SEO Manager bulk-editing page |
admin-next/panels/seo-manager.js |
The in-editor SEO panel |
tests/run.php, tests/bootstrap.php, phpstan.neon.dist |
Tests and static analysis |
Licence
MIT.

