This plugins handles the generation of meta tags for search engines, social networks, browsers and beyond.
The plugin looks for metadata in a page's content file (e.g. article.txt). If the page does not contain the specific field, it checks if the page model provides a metadata()
method returning an arraywith corresponding data. If that also fails, it falls back to default metadata stored in the site.txt
.
Description: The description field is used for search engines as a plain meta tag and additionally added as an OpenGraph meta tag, which is used by social media networks like e.g. Facebook or Twitter.
Thumbnail: The thumbnail for sharing the page in a social network. See below for all options.
Twittercard: Is "summary_large_image" by default. Set this to "summary", if you don’t want to display a large preview image.
Robots: Generates the "robots" meta tag, that gives specifix instructions to crawlers. By default, this tag is not preset, unless a default value is defined in site.txt
. Use a value, that you would also use if you wrote the markup directly (e.g. noindex, nofollow
)
Title and Ogtitle: By default, the metadata plugin will use the page’s title
field. You can override this by defining an ogtitle
field for a specific page. The ogtitle
will then be used for OpenGraph metadata instead of the page title.
Twittersite: The twitter account, which the site belongs to.
Twittercreator: The twitter account, who created the current page.
Priority: The priority for telling search engines about the importance of pages of your site. Must be a float value between 0.0 and 1.0. This value will not fall back to site.txt
, but rather use 0.5 as default.
Changefreq: Tells search engines how often a page changes. Possible values can be found in the (sitemaps protocol specification)[https://www.sitemaps.org/protocol.html].
Page models can be useful, if you do not want to enter all meta data manually.
The following example adds a metadata()
method to all Kosmos episodes, that takes care of generating useful metadata. All keys returned by the metadata()
method must be lowercase.
You can still override values (e.g. description
) by adding a description field to an episode’s issue.txt
file if you want to customize any of these values.
class KosmosIssuePage extends Page
{
public function metadata(): array
{
return [
'description' => 'Read issue no. ' . $this->uid() . ' of our montly newsletter online.',
'ogtitle' => 'Kirby Kosmos Episode ' . $this->uid(),
];
}
}
This plugin also provides automatic generated thumbnails for e.g. social networks. By default every page gets an automatic thumbnail. You can switch this off:
Thumbnail: false
public function metadata(): array
{
return [
'thumbnail' => false
];
}
Another option is to define a custom thumbnail for the page/page model:
OgImage: assets.png
public function metadata(): array
{
return [
'ogimage' => $this->image()
];
}
The autogenerated thumbnails have some defaults for the lead
and title
text string:
lead
: bradcrumb of parents' page titles. If none,The CMS
title
: the page's title
You can also modiy these per page or page model:
Thumbnail:
-
lead: Check out our
title: Amazing sale
public function metadata(): array
{
return [
'thumbnail' => [
'lead' => 'Reference / Class',
'title' => $this->name()
]
];
}
The autogenerated thumbnail can also optionally include an image:
Thumbnail: assets.png
Thumbnail:
-
lead: The CMS
image: assets.png
public function metadata(): array
{
return [
'thumbnail' => [
'image' => $this->image()
]
];
}