Kirby Page Method to add code into the HTML Head using snippets.
This plugin is free but if you use it in a commercial project please consider to make a donation 🍻.
- basic metatags
- rss feed
- opengraph
- google analytics with anonymize IP
- google webfonts
- typekit
- a11y.css when
c::set('debug', true);
- Kirby 2.3+
kirby plugin:install bnomei/kirby-htmlhead
$ git submodule add https://github.com/bnomei/kirby-htmlhead.git site/plugins/kirby-htmlhead
- Download the contents of this repository as ZIP-file.
- Rename the extracted folder to
kirby-htmlhead
and copy it into thesite/plugins/
directory in your Kirby project.
In any template or your header
snippet call the page method right after the tags that should come first.
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<base href="<?= site()->url() ?>'">'
<link rel="canonical" href="<?= $page->url() ?>">'
<title><?= $page->title() ?></title>
<?= $page->htmlhead_snippets() ?>
Or if you would use these meta tags anyway you can use
<?= $page->htmlhead_alpha($page->title()) ?>
<?= $page->htmlhead_snippets() ?>
If you have your own snippets you want to have called at the header simply add them to the plugin.htmlhead.snippets
setting.
You can set these in your site/config/config.php
or in your template code since $page
has to exist.
- default: []
- this will call all snippets of this plugin. add the filename of your snippet without its extension.
- default:
c::set('plugin.htmlhead.seo', [
'author' => str::unhtml($page->head_author()),
'description' => str::unhtml($page->head_description()),
'robots' => 'index, follow, noodp',
]);
- you can use a Kirby Page Model or Kirby Page Methods to provide the values
head_author
andhead_description
easily – see examples below. - if you need more control consider using kirby-meta-tags instead.
- default:
c::set('plugin.htmlhead.opengraph', [
'og:title' => str::unhtml($page->title()),
'og:type' => 'website',
'og:url' => $page->url(),
'og:image' => $page->hasImages() ? $page->images()->first()->resize(470)->url() : null,
'og:site_name' => site()->title(),
'og:description' => str::unhtml($page->head_description()),
'og:locale' => str_replace('.UTF8','',site()->locale()),
'article:author' => str::unhtml($page->head_author()),
]);
- set to
false
you do not need opengraph from this plugin. you can use a Kirby Page Models or Kirby Page Methods to provide the valueshead_author
andhead_description
easily – see examples below. - if you need more control consider using kirby-meta-tags instead.
- default: false
- URI for
application/rss+xml
feed page object.
- default: false
- set your typkit id to load your fonts async.
- default: []
- array of google font family names. like
Lato:400,700
.
- default: 'UA-'
- your google analytics id.
- default:
true
- will set
anonymizeIp
if enabled.
- default: c::get('debug', false)
- a11y.css will only be loaded if debug is enabled.
- default: 'https://rawgit.com/ffoodd/a11y.css/master/css/a11y-en.css'
- set this any other a11y.css configuration or to
false
if you want to disable a11y.css.
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.
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.
Technical support is provided on GitHub only. No representations or guarantees are made regarding the response time in which support questions are answered. But you can also join the discussions in the Kirby Forum.