johannschopplich / kirby-serp-preview
Kirby Panel plugin for search engine result page previews
Package info
github.com/johannschopplich/kirby-serp-preview
Type:kirby-plugin
pkg:composer/johannschopplich/kirby-serp-preview
Fund package maintenance!
Requires
Requires (Dev)
- getkirby/cms: ^5
README
Kirby SERP Preview
See exactly how your pages will appear in Google search results β updating live as you edit, right in the Kirby Panel.
Features
- β‘ Live preview that updates as you type
- π― Google-style search result snippet in the Panel
- π Dark and light mode β adapts to the Panel theme with Google's own colors
- π§© Kirby query language support in configuration
- πΊοΈ Multi-language ready
- βοΈ Custom formatters for title and description
- π Optional Google Search Console link
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 shows:
- 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
Options marked 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 a custom title (e.g. metaTitle) |
defaultTitle |
β | Yes | Fallback title if titleContentKey is empty |
descriptionContentKey |
β | No | Field name for a custom description (e.g. metaDescription) |
defaultDescription |
β | Yes | Fallback description if descriptionContentKey is empty |
searchConsoleUrl |
β | No | Shows a link button to Google Search Console |
Title & Description Resolution
Title resolves in this order:
- Value of the
titleContentKeyfield, if set defaultTitle, if configured- Page title + separator + site title (e.g.
About Us β My Website)
Description resolves in this order:
- Value of the
descriptionContentKeyfield, if set defaultDescription, if configured- No description shown
Custom Formatters
Transform the title and description before they are displayed β useful for truncating text, stripping HTML, or applying other adjustments. Formatters are defined in your configuration and receive the current value and the page object, so transformations can be page-specific:
// site/config/config.php use Kirby\Toolkit\Str; return [ 'johannschopplich.serp-preview' => [ 'formatters' => [ 'title' => function (string $value, \Kirby\Cms\Page $page) { // Example: limit the title length return Str::short($value, 60); }, 'description' => function (string $value, \Kirby\Cms\Page $page) { // Example: strip HTML and limit the length return Str::short(strip_tags($value), 160); } ] ] ];
License
MIT License Β© 2023-PRESENT Johann Schopplich
MIT License Β© 2023 Dennis Baum
