Navigation Menu

Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

bnomei/kirby-htmlhead

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kirby HTML Head

GitHub release License Kirby Version

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 🍻.

Key Features

  • basic metatags
  • rss feed
  • opengraph
  • google analytics with anonymize IP
  • google webfonts
  • typekit
  • a11y.css when c::set('debug', true);

Can used in combination with...

Requirements

Installation

kirby plugin:install bnomei/kirby-htmlhead

Git Submodule

$ git submodule add https://github.com/bnomei/kirby-htmlhead.git site/plugins/kirby-htmlhead

Copy and Paste

  1. Download the contents of this repository as ZIP-file.
  2. Rename the extracted folder to kirby-htmlhead and copy it into the site/plugins/ directory in your Kirby project.

Usage

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.

Setting

You can set these in your site/config/config.php or in your template code since $page has to exist.

plugin.htmlhead.snippets

  • default: []
  • this will call all snippets of this plugin. add the filename of your snippet without its extension.

plugin.htmlhead.seo (template only)

  • default:
c::set('plugin.htmlhead.seo', [
  'author'      => str::unhtml($page->head_author()),
  'description' => str::unhtml($page->head_description()),
  'robots'      => 'index, follow, noodp',
]);

plugin.htmlhead.opengraph (template only)

  • 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 values head_author and head_description easily – see examples below.
  • if you need more control consider using kirby-meta-tags instead.

plugin.htmlhead.feed

  • default: false
  • URI for application/rss+xml feed page object.

plugin.htmlhead.typekit

  • default: false
  • set your typkit id to load your fonts async.

plugin.htmlhead.googlewebfonts

  • default: []
  • array of google font family names. like Lato:400,700.

plugin.htmlhead.googleanalytics

  • default: 'UA-'
  • your google analytics id.

plugin.htmlhead.googleanalytics.anonymizeIp

  • default: true
  • will set anonymizeIp if enabled.

plugin.htmlhead.a11ycss.debugOnly

  • default: c::get('debug', false)
  • a11y.css will only be loaded if debug is enabled.

plugin.htmlhead.a11ycss

Examples

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

MIT

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

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.