# Kirby Meta Tags [](https://github.com/wearejust/kirby-meta-tags/releases) [](https://github.com/wearejust/kirby-meta-tags/issues) HTML meta tags generator for Kirby. Supports [Open Graph](http://ogp.me), [Twitter Cards](https://dev.twitter.com/cards/overview), and [JSON Linked Data](https://json-ld.org) out of the box. ## Requirements - Kirby 3 - PHP 8.0 ## Installation ### Download Download and copy this repository to `site/plugins/meta-tags`. ### Composer ``` composer require wearejust/kirby-meta-tags ``` ## Basic Usage After installing the Meta Tags plugin, you need to add one line to the `head` element on your template, or `header.php` snippet: ```diff
+ metaTags() ?> ``` By default the `metaTags` page method will render all tag groups at once. But you can also render only one tag at a time: ```php metaTags('title') ?> ``` Or specify which tags to render: ```php metaTags(['og', 'twitter', 'json-ld']) ?> ``` ### Default The plugin ships with some default meta tags enabled for your convenience: ```php return [ // other options... 'wearejust.meta-tags.default' => function ($page, $site) { return [ 'title' => $site->title(), 'meta' => [ 'description' => $site->description() ], 'link' => [ 'canonical' => $page->url() ], 'og' => [ 'title' => $page->isHomePage() ? $site->title() : $page->title(), 'type' => 'website', 'site_name' => $site->title(), 'url' => $page->url() ] ]; } ] ``` **The `wearejust.meta-tags.default` option is applied to all pages on your Kirby site.** Of course you can change the defaults. In order to do that, just copy this example to your `site/config/config.php` file and tweak it to fit your website needs. ### Templates Following the flexible spirit of Kirby, you also have the option to add template specific meta tags: ```php return [ // other options... 'wearejust.meta-tags.templates' => function ($page, $site) { return [ 'song' => [ 'og' => [ 'type' => 'music.song', 'namespace:music' => [ 'duration' => $page->duration(), 'album' => $page->parent()->url(), 'musician' => $page->singer()->html() ] ] ] ]; } ] ``` In the example above, those settings will only be applied to pages which template is `song`. For more information on all the `meta`, `link`, Open Graph and Twitter Card tags available, check out these resources: - [`` Cheat Sheet](http://gethead.info) - [Open Graph](http://ogp.me) - [Twitter Cards](https://dev.twitter.com/cards/overview) ## Options Both the `wearejust.meta-tags.default` and `wearejust.meta-tags.templates` accept similar values: ### `wearejust.meta-tags.default` It accepts an array containing any or all of the following keys: `title`, `meta`, `link`, `og`, and `twitter`. With the exception of `title`, all other groups must return an array of key-value pairs. Check out the [tag groups](#tag-groups) section to learn which value types are accepted by each key. ```php 'wearejust.meta-tags.default' => function ($page, $site) { return [ 'title' => 'Site Name', 'meta' => [ /* meta tags */ ], 'link' => [ /* link tags */ ], 'og' => [ /* Open Graph tags */ ], 'twitter' => [ /* Twitter Card tags */ ], 'json-ld' => [ /* JSON-LD schema */ ], ]; } ``` ### `wearejust.meta-tags.templates` This option allows you to define a template specific set of meta tags. It must return an array where each key corresponds to the template name you are targeting. ```php 'wearejust.meta-tags.templates' => function ($page, $site) { return [ 'article' => [ /* tags groups */ ], 'about' => [ /* tags groups */ ], 'products' => [ /* tags groups */ ], ]; } ``` When a key matches the current page template name, it is merged and overrides any repeating properties defined on the `wearejust.meta-tags.default` option so you don't have to repeat yourself. ## Tag Groups These groups accept string, closure, or array as their values. Being so flexible, the sky is the limit to what you can do with Meta Tags! ### `title` Corresponds to the HTML ````html ```
```html ```
```html ```
```html
```html ```
```html ```