johannschopplich / kirby-serp-preview
Kirby Panel plugin for search engine result page previews
Fund package maintenance!
kirby.tools
Installs: 1 733
Dependents: 0
Suggesters: 0
Security: 0
Stars: 27
Watchers: 2
Forks: 2
Open Issues: 0
Type:kirby-plugin
pkg:composer/johannschopplich/kirby-serp-preview
Requires
Requires (Dev)
- getkirby/cms: ^4 || ^5
README
Kirby SERP Preview
Preview how your pages will appear in Google search results, directly in the Kirby Panel.
Features
- π― Google-style search result preview in the Panel
- π Dark and light mode support (adapts to Panel theme)
- π§© Kirby query language support in configuration
- πΊοΈ Multi-language ready
- βοΈ Custom formatters for title and description
- π Optional Google Search Console link
Tip
Ready for Kirby 5! The plugin adapts to the Panel theme and uses Google's dark mode colors.
Requirements
- Kirby 4 or Kirby 5
Installation
Composer
composer require johannschopplich/kirby-serp-preview
Download
Download and copy this repository to /site/plugins/kirby-serp-preview.
Quick Start
Add the section to any page blueprint:
sections: serp-preview: type: serp-preview
That's it! The preview will show:
- Title: Page title + separator + site title
- URL: Your site URL + page path
- Description: Empty (until configured)
Configuration
Full Example
sections: serp-preview: type: serp-preview # Site information siteTitle: "{{ site.title.value }}" siteUrl: "{{ kirby.url }}" faviconUrl: "{{ site.favicon.toFile.url }}" titleSeparator: "-" # Custom title (overrides default) titleContentKey: metaTitle defaultTitle: "{{ page.title.value }}" # Custom description descriptionContentKey: metaDescription defaultDescription: "{{ site.metaDescription.value }}" # Optional searchConsoleUrl: "https://search.google.com/search-console"
Options Reference
Options marked with Query support Kirby's query language, e.g. {{ site.title.value }}.
| Option | Default | Query | Description |
|---|---|---|---|
siteTitle |
{{ site.title.value }} |
Yes | Site name shown in the preview |
siteUrl |
{{ kirby.url }} |
Yes | Site URL shown in the preview |
faviconUrl |
β | Yes | URL to your favicon |
titleSeparator |
β |
Yes | Separator between page title and site title |
titleContentKey |
β | No | Field name for custom title (e.g. metaTitle) |
defaultTitle |
β | Yes | Fallback title if titleContentKey is empty |
descriptionContentKey |
β | No | Field name for custom description (e.g. metaDescription) |
defaultDescription |
β | Yes | Fallback description if descriptionContentKey is empty |
searchConsoleUrl |
β | No | Shows a link button to Google Search Console |
How It Works
Title Resolution
The preview title is determined in this order:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β 1. titleContentKey field has value? β
β ββ YES β Use field value β
β ββ NO β β
β β
β 2. defaultTitle is configured? β
β ββ YES β Use defaultTitle (query supported) β
β ββ NO β β
β β
β 3. Fallback: Page Title + Separator + Site Title β
β β "About Us β My Website" β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Description Resolution
The preview description is determined in this order:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β 1. descriptionContentKey field has value? β
β ββ YES β Use field value β
β ββ NO β β
β β
β 2. defaultDescription is configured? β
β ββ YES β Use defaultDescription (query supported) β
β ββ NO β No description shown β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Custom Formatters
You can transform the title and description before they are displayed using custom formatters. This is useful for truncating text, removing HTML, or applying other transformations.
// site/config/config.php return [ 'johannschopplich.serp-preview' => [ 'formatters' => [ 'title' => function (string $value, \Kirby\Cms\Page $page) { // Example: Limit title length return Str::short($value, 60); }, 'description' => function (string $value, \Kirby\Cms\Page $page) { // Example: Strip HTML and limit length return Str::short(strip_tags($value), 160); } ] ] ];
The formatter receives the current value and the page object, allowing page-specific transformations.
License
MIT License Β© 2023-PRESENT Johann Schopplich
MIT License Β© 2023 Dennis Baum
