- PHP 51.2%
- JavaScript 48.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| assets | ||
| snippets | ||
| .DS_Store | ||
| composer.json | ||
| index.php | ||
| LICENSE | ||
| README.md | ||
Kirby Sharehelper
Kirby Sharehelper is a small Kirby CMS plugin that renders a reusable share button for the browser's Web Share API (navigator.share). It supports sharing the current page URL, custom titles and text, and optional image/file URLs on devices and browsers that support file sharing.
Features
- Reusable Kirby snippet for share buttons
- Uses the native Web Share API where available
- Optional sharing of Kirby files or public file URLs
- Automatic JavaScript asset loading once per page
- German and English default translations
- Progressive fallback: the button is hidden when
navigator.shareis unavailable
Requirements
- PHP 8.1 or newer
- Kirby 4 or Kirby 5
- HTTPS in production, as required by the Web Share API in most browsers
- A browser/device that supports
navigator.share
File sharing support depends on the browser. The plugin checks navigator.canShare() before invoking the native share dialog.
Installation
Composer
composer require justin/kirby-sharehelper
Composer installs the plugin into site/plugins/kirby-share-helper via Kirby's Composer installer.
If the package is hosted in the Forgejo Composer registry instead of Packagist, add the registry first:
composer config repositories.kirby-sharehelper composer https://forgejo.justinritter.de/api/packages/justin/composer
composer require justin/kirby-sharehelper
Manual Installation
Download or clone this repository into your Kirby installation:
git clone https://forgejo.justinritter.de/justin/kirby-sharehelper.git site/plugins/kirby-share-helper
The plugin directory must contain the index.php file directly at its root.
Usage
Render the share button in a template or snippet:
<?php snippet('general_share_button') ?>
By default, the snippet shares the current page URL and uses the translated button label.
Custom Share Data
<?php snippet('general_share_button', [
'title' => $page->title()->value(),
'text' => $page->description()->or('Read this page')->value(),
'url' => $page->url(),
]) ?>
Custom Button Markup
<?php snippet('general_share_button', [
'id' => 'article-share',
'class' => ['button', 'button-share'],
'label' => 'Share article',
'loadingLabel' => 'Preparing share...',
]) ?>
Share Files
Pass either a Kirby file object, a public file URL, or an array of both:
<?php snippet('general_share_button', [
'title' => $page->title()->value(),
'text' => 'Take a look at this image',
'url' => $page->url(),
'files' => $page->image(),
]) ?>
<?php snippet('general_share_button', [
'files' => [
$page->image('cover.jpg'),
'https://example.com/public-image.jpg',
],
]) ?>
Files must be publicly reachable by the visitor's browser. The plugin fetches the file URL in the browser and passes the resulting File object to the Web Share API.
Snippet Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
class |
`string | array | null` |
id |
`string | null` | null |
title |
`string | null` | null |
text |
string |
'' |
Share text. |
url |
`string | null` | Current page URL |
files |
`Kirby\Cms\File | string | array |
label |
string |
Translated "Share" label | Button text. |
loadingLabel |
string |
Translated loading label | Button text while file data is prepared. |
Styling
The rendered button always includes the kirby-share-button class:
.kirby-share-button {
cursor: pointer;
}
Pass your own class via the class parameter to integrate the button into your site's design system.
Translations
The plugin registers these translation keys:
nodework.sharehelper.sharenodework.sharehelper.share.failednodework.sharehelper.share.loading
Override them in your Kirby language files if needed.
Publishing With Composer
The package is prepared as a Kirby Composer plugin via:
type: kirby-plugingetkirby/composer-installerextra.installer-name: kirby-share-helper
Create releases with Git tags:
git tag 1.0.0
git push --tags
Then publish the repository on Packagist or upload a ZIP archive with the composer.json to Forgejo's Composer package registry.
License
Kirby Sharehelper is licensed under the GNU Affero General Public License v3.0 or later.
Copyright (C) 2026 Justin Ritter @Nodework