You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+67-95Lines changed: 67 additions & 95 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,43 +3,8 @@
3
3
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.
4
4
5
5
## Requirements
6
-
- Kirby 2.3.2+
7
-
- PHP 5.4+
8
-
9
-
## Installation
10
-
11
-
### Download
12
-
[Download the files](https://github.com/pedroborges/kirby-meta-tags/archive/master.zip) and place them inside `site/plugins/meta-tags`.
13
-
14
-
### Kirby CLI
15
-
Kirby's [command line interface](https://github.com/getkirby/cli) is the easiest way to install the Meta Tags plugin:
After installing the Meta Tags plugin, you need to add one line to the `head` element on your template, or `header.php` snippet:
@@ -65,53 +30,56 @@ Or specify which tags to render:
65
30
```
66
31
67
32
### Default
68
-
69
33
The plugin ships with some default meta tags enabled for your convenience:
70
34
71
35
```php
72
-
c::set('meta-tags.default', function(Page $page, Site $site) {
73
-
return [
74
-
'title' => $site->title(),
75
-
'meta' => [
76
-
'description' => $site->description()
77
-
],
78
-
'link' => [
79
-
'canonical' => $page->url()
80
-
],
81
-
'og' => [
82
-
'title' => $page->isHomePage()
83
-
? $site->title()
84
-
: $page->title(),
85
-
'type' => 'website',
86
-
'site_name' => $site->title(),
87
-
'url' => $page->url()
88
-
]
89
-
];
90
-
});
36
+
return [
37
+
// other options...
38
+
'pedroborges.metatags.default' => function ($page, $site) {
39
+
return [
40
+
'title' => $site->title(),
41
+
'meta' => [
42
+
'description' => $site->description()
43
+
],
44
+
'link' => [
45
+
'canonical' => $page->url()
46
+
],
47
+
'og' => [
48
+
'title' => $page->isHomePage()
49
+
? $site->title()
50
+
: $page->title(),
51
+
'type' => 'website',
52
+
'site_name' => $site->title(),
53
+
'url' => $page->url()
54
+
]
55
+
];
56
+
}
57
+
]
91
58
```
92
59
93
-
**The `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.
94
-
95
-
> If your configuration file grows too much, you can extract it to a `site/config/meta-tags.php` file, for example, and require it from `site/config/config.php`.
60
+
**The `pedroborges.metatags.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.
96
61
97
62
### Templates
98
63
Following the flexible spirit of Kirby, you also have the option to add template specific meta tags:
99
64
100
65
```php
101
-
c::set('meta-tags.templates', function(Page $page, Site $site) {
102
-
return [
103
-
'song' => [
104
-
'og' => [
105
-
'type' => 'music.song',
106
-
'namespace:music' => [
107
-
'duration' => $page->duration(),
108
-
'album' => $page->parent()->url(),
109
-
'musician' => $page->singer()->html()
66
+
return [
67
+
// other options...
68
+
'pedroborges.metatags.templates' => function ($page, $site) {
69
+
return [
70
+
'song' => [
71
+
'og' => [
72
+
'type' => 'music.song',
73
+
'namespace:music' => [
74
+
'duration' => $page->duration(),
75
+
'album' => $page->parent()->url(),
76
+
'musician' => $page->singer()->html()
77
+
]
110
78
]
111
79
]
112
-
]
113
-
];
114
-
});
80
+
];
81
+
}
82
+
]
115
83
```
116
84
117
85
In the example above, those settings will only be applied to pages which template is `song`.
@@ -123,34 +91,38 @@ For more information on all the `meta`, `link`, Open Graph and Twitter Card tags
Both the `meta-tags.default` and `meta-tags.templates` accept similar values:
94
+
Both the `pedroborges.metatags.default` and `pedroborges.metatags.templates` accept similar values:
127
95
128
-
### `meta-tags.default`
96
+
### `pedroborges.metatags.default`
129
97
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.
130
98
131
99
```php
132
-
c::set('meta-tags.default', [
133
-
'title' => 'Site Name',
134
-
'meta' => [ /* meta tags */ ],
135
-
'link' => [ /* link tags */ ],
136
-
'og' => [ /* Open Graph tags */ ],
137
-
'twitter' => [ /* Twitter Card tags */ ],
138
-
'json-ld' => [ /* JSON-LD schema */ ],
139
-
]);
100
+
'pedroborges.metatags.default' => function ($page, $site) {
101
+
return [
102
+
'title' => 'Site Name',
103
+
'meta' => [ /* meta tags */ ],
104
+
'link' => [ /* link tags */ ],
105
+
'og' => [ /* Open Graph tags */ ],
106
+
'twitter' => [ /* Twitter Card tags */ ],
107
+
'json-ld' => [ /* JSON-LD schema */ ],
108
+
];
109
+
}
140
110
```
141
111
142
-
### `meta-tags.templates`
112
+
### `pedroborges.metatags.templates`
143
113
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.
144
114
145
115
```php
146
-
c::set('meta-tags.templates', [
147
-
'article' => [ /* tags groups */ ],
148
-
'about' => [ /* tags groups */ ],
149
-
'products' => [ /* tags groups */ ],
150
-
]);
116
+
'pedroborges.metatags.default' => function ($page, $site) {
117
+
return [
118
+
'article' => [ /* tags groups */ ],
119
+
'about' => [ /* tags groups */ ],
120
+
'products' => [ /* tags groups */ ],
121
+
];
122
+
}
151
123
```
152
124
153
-
When a key matches the current page template name, it is merged and overrides any repeating properties defined on the `meta-tags.default` option so you don't have to repeat yourself.
125
+
When a key matches the current page template name, it is merged and overrides any repeating properties defined on the `pedroborges.metatags.default` option so you don't have to repeat yourself.
154
126
155
127
## Tag Groups
156
128
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!
@@ -197,7 +169,7 @@ This tag group is used to render HTML `<link>` elements. It takes an `array` of
0 commit comments