bnomei / kirby3-htmlhead
Kirby 3 Plugin for a best-practice HTML Head Element extendable with snippets.
Fund package maintenance!
bnomei
Patreon
buymeacoff.ee/bnomei
paypal.me/bnomei
Installs: 3 376
Dependents: 0
Suggesters: 1
Security: 0
Stars: 20
Watchers: 1
Forks: 0
Open Issues: 2
Type:kirby-plugin
Requires
- php: >=8.0.0
- getkirby/composer-installer: ^1.1
Requires (Dev)
- getkirby/cms: ^3.6
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^8.3
Suggests
- PaulMorel/kirby3-fathom-analytics: A Kirby 3 plugin for integrating the privacy focused Fathom Analytics service to your site
- bnomei/kirby3-feed: Add xml-rss and/or json feed
- bnomei/kirby3-fingerprint: Cachebusting for css/js or any other file using query-string or redirect
- bnomei/kirby3-mobile-detect: Helper to detect device
- bnomei/kirby3-redirects: Add http status redirects for any URI (not just Kirby Routes). Perfect when porting a non kirby site
- bnomei/kirby3-robots-txt: Automatic robots.txt. Detects omz13/kirby3-xmlsitemap
- bnomei/kirby3-security-headers: CPS headers to make the the web a saver place. Sensible defaults with zero configuration
- fabianmichael/kirby-meta: Add OpenGraph, Twitter Cards and JSON-ld among other metatags
- omz13/kirby3-wellknown: Add wellknowns like robots.txt, humans.txt, security.txt, dnt-policy and others
- sylvainjule/kirby-matomo: Generate a tracking code for Matomo, and displays some useful metrics directly within the panel
- dev-master
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.0
- 2.1.13
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.7.8
- 1.7.7
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.6
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.4
- 1.5.2
- 1.5.1
- dev-dependabot/composer/guzzlehttp/psr7-2.5.0
This package is auto-updated.
Last update: 2024-11-06 16:01:18 UTC
README
Kirby 3 Plugin for a best-practice HTML Head Element extendable with snippets.
Commercial Usage
Support open source!
This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?
Be kind. Share a little. Thanks.
‐ Bruno
Installation
- unzip master.zip as folder
site/plugins/kirby3-htmlhead
or git submodule add https://github.com/bnomei/kirby3-htmlhead.git site/plugins/kirby3-htmlhead
orcomposer require bnomei/kirby3-htmlhead
Works well with
- fabianmichael/kirby-meta to add OpenGraph and JSON-ld
- and some of my other Plugins
Usage
Site Method: attrLang
There is a language helper available as well.
<?php ?> <html <?= site()->langAttr() ?>> <!-- ... --> </html>
Page Method: htmlhead
In any template or your header
snippet call the page method right after the tags that should come first.
<!DOCTYPE html> - <html> + <html <?= site()->langAttr() ?>> <head> - <meta charset="utf-8"> - <meta http-equiv="x-ua-compatible" content="ie=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1 shrink-to-fit=no"> - <base href="<?= site()->url() ?>'">' - <title><?= $page->title() ?></title> + <?= $page->htmlhead() ?>
You can also override any defaults in forwarding the new or additional data to the page method.
<?= $page->htmlhead([ // override defaults 'htmlhead/meta-description' => function ($kirby, $site, $page) { return Str::unhtml($page->myDescriptionField()->kti()); }, // add new 'htmlhead/link-feedrss' => function ($kirby, $site, $page) { return []; // use defaults of snippet }, ]) ?>
But I would recommend that you configure which snippets are use with the config settings (see below).
Setting
There is only one setting called bnomei.htmlhead.snippets
and it takes an array of callbacks. It has sensible defaults but you can add any of the provided snippets or your own snippets. The unittests for this plugin have a more specific example for you to explore.
https://github.com/bnomei/kirby3-htmlhead/blob/master/tests/config/config.php
<?php return [ 'bnomei.htmlhead.snippets' => [ /******************************** * IMPORTANT: order matters! based on research from @csswizardry */ 'htmlhead/recommended-minimum' => null, 'htmlhead/title' => function ($kirby, $site, $page) { return ['title' => $page->title()]; }, // async first then sync js scripts 'htmlhead/script-js' => function ($kirby, $site, $page) { return ['files' => [ '/assets/app.js' ]]; }, 'htmlhead/link-css' => function ($kirby, $site, $page) { return ['files' => ['/assets/app.css']]; }, 'htmlhead/link-preload' => function ($kirby, $site, $page) { return ['files' => ['/assets/app.css', '/endpoint/data.json']]; }, // deferred scripts after sync css is faster 'htmlhead/script-js-defer' => function ($kirby, $site, $page) { return ['files' => [ [ 'src' => '//unpkg.com/alpinejs', 'defer' => true, ], ]]; }, 'htmlhead/link-prefetch' => function ($kirby, $site, $page) { return ['files' => ['/assets/next-page.js']]; }, 'htmlhead/base' => function ($kirby, $site, $page) { return ['href' => kirby()->site()->url()]; }, 'htmlhead/meta-robots' => function ($kirby, $site, $page) { return ['content' => 'index, follow, noodp']; }, 'htmlhead/meta-author' => function ($kirby, $site, $page) { return ['content' => $site->author()]; }, 'htmlhead/meta-description' => function ($kirby, $site, $page) { return ['content' => Str::unhtml($page->seodesc())]; }, 'htmlhead/link-feedrss' => function ($kirby, $site, $page) { // defaults return [ 'url' => url('/feed'), 'title' => $page->title(), ]; }, 'htmlhead/link-feedrss' => function ($kirby, $site, $page) { // defaults return [ 'url' => url('/feed'), 'title' => $page->title(), ]; }, ], // ... other options ];
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.