feat: intégration plugin Kirby SEO
All checks were successful
Deploy / Deploy to Production (push) Successful in 22s
All checks were successful
Deploy / Deploy to Production (push) Successful in 22s
- Ajout de tobimori/kirby-seo via Composer
- snippet('seo/head') dans header.php (remplace les meta manuels)
- snippet('seo/schemas') dans footer.php pour JSON-LD
- Onglet SEO ajouté dans site.yml et tous les blueprints de pages
- Configuration SEO dans config.php (sitemap, robots, canonicalBase TODO)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
baab2fb3a1
commit
58c31ea391
133 changed files with 9201 additions and 253 deletions
|
|
@ -0,0 +1,84 @@
|
|||
---
|
||||
title: Programmatic Content
|
||||
intro: Set default SEO values from page models
|
||||
---
|
||||
|
||||
Sometimes you want SEO fields to default to values from other fields, or generate them from code. A common example is using a plugin like [kirby-paparazzi](https://github.com/tobimori/kirby-paparazzi) to generate OG images for every page.
|
||||
|
||||
Add a `metaDefaults` method to a [page model](https://getkirby.com/docs/guide/templates/page-models). It returns an array of meta tag names mapped to their values. These defaults apply through the [Meta Cascade](0_getting-started/1_your-first-meta-tags) when no editor override exists.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// site/models/article.php
|
||||
|
||||
use Kirby\Cms\Page;
|
||||
|
||||
class ArticlePage extends Page
|
||||
{
|
||||
public function metaDefaults(string $lang = null): array
|
||||
{
|
||||
return [
|
||||
'og:image' => "{$this->url()}.png",
|
||||
'og:image:width' => 1230,
|
||||
'og:image:height' => 600,
|
||||
'description' => $this->content($lang)->summary()->value(),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Kirby SEO picks the correct tag syntax from the name. Open Graph keys (starting with `og:`) get `property` and `content` attributes, link keys like `canonical` get `rel` and `href`, and everything else gets `name` and `content`.
|
||||
|
||||
## Custom tag attributes
|
||||
|
||||
If you need full control over a tag's output, pass an array with `tag` and `attributes`:
|
||||
|
||||
```php
|
||||
return [
|
||||
// shorthand
|
||||
'description' => 'A page about something',
|
||||
|
||||
// tag with inner content
|
||||
[
|
||||
'tag' => 'title',
|
||||
'content' => 'My Page Title',
|
||||
],
|
||||
|
||||
// tag with attributes
|
||||
[
|
||||
'tag' => 'meta',
|
||||
'attributes' => [
|
||||
'property' => 'og:image:alt',
|
||||
'content' => "An image of {$this->title()}",
|
||||
],
|
||||
],
|
||||
|
||||
// link tag
|
||||
[
|
||||
'tag' => 'link',
|
||||
'attributes' => [
|
||||
'rel' => 'preconnect',
|
||||
'href' => 'https://fonts.googleapis.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
## Global defaults via a plugin
|
||||
|
||||
Page models only apply to pages with a specific template. If you want to add meta tags to all pages, you can register a `metaDefaults` [page method](https://getkirby.com/docs/reference/plugins/extensions/page-methods) in a plugin:
|
||||
|
||||
```php
|
||||
<?php
|
||||
// site/plugins/my-meta/index.php
|
||||
|
||||
Kirby::plugin('my/meta', [
|
||||
'pageMethods' => [
|
||||
'metaDefaults' => function (string $lang = null): array {
|
||||
return [
|
||||
'og:image' => "{$this->url()}.png",
|
||||
];
|
||||
},
|
||||
],
|
||||
]);
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue