General Metadata
The general metadata builder provides various methods to add common metadata information to your site, such as keywords, titles, and descriptions.
To access the general metadata builder using the Metadata
facade, we can call the general
method:
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5Metadata::general();
The general builder provides the following methods to add meta/link tags to your site.
#Charset
The charset
method queues a <meta charset="..." >
tag. It defaults to utf-8
, but can be overridden:
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5Metadata::general()->charset();
6Metadata::general()->charset('ascii');
7Metadata::general()->charset(function (array $context) {
8 return 'utf-8';
9});
#Description
The description
method queues a <meta name="description" content"...">
tag. By default it binds to the $meta_description
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_description', function (array $context) {
7 return 'The best website ever.';
8});
9
10// Changing which variable is used.
11Metadata::general()->description('$seo_description');
#Keywords
The keywords
method queues a <meta name="keywords" content="...">
tag. By default it binds to the $meta_keywords
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_keywords', function (array $context) {
7 return 'keyword1, keyword2';
8});
9
10// Changing which variable is used.
11Metadata::general()->keywords('$seo_keywords');
#Author
The author
method queues a <meta name="author" content="...">
tag. By default it binds to the $meta_author
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_author', function (array $context) {
7 // Retrieve author information from the context.
8
9 return $context['author'];
10});
11
12// Changing which variable is used.
13Metadata::general()->author('$the_author_field');
#HTTP Equivalent
The httpEquiv
method queues a <meta http-equiv="..." content="...">
tag.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5Metadata::general()->httpEquiv('refresh', '30');
#X-UA-Compatible
The xUaCompatible
helper method queues a <meta http-equiv="X-UA-Compatible" content="...">
tag. By default it uses IE=edge
as the content.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5Metadata::general()->xUaCompatible();
#Title
The title
method queues a <title></title>
tag. By default it binds to the $title
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('title', function (array $context) {
7 return 'A super awesome title.';
8});
9
10// Changing which variable is used.
11Metadata::general()->title('$seo_title');
#Canonical Link
The canonical
method queues a <link rel="canonical" href="...">
meta tag. By default it binds to the $meta_canonical
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_canonical', function (array $context) {
7 return 'the-url-here';
8});
9
10// Changing which variable is used.
11Metadata::general()->canonical('$the_canonical_field');
#First Link
The first
method queues a <link rel="first" href="...">
tag. By default it binds to the $meta_link_first
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_link_first', function (array $context) {
7 return 'the-url-here';
8});
9
10// Changing which variable is used.
11Metadata::general()->first('$the_link_first_field');
#Last Link
The last
method queues a <link rel="last" href="...">
tag. By default it binds to the $meta_link_last
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_link_last', function (array $context) {
7 return 'the-url-here';
8});
9
10// Changing which variable is used.
11Metadata::general()->last('$the_link_last_field');
#Previous Link
The prev
method queues a <link rel="prev" href="...">
tag. By default it binds to the $meta_link_prev
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_link_prev', function (array $context) {
7 return 'the-url-here';
8});
9
10// Changing which variable is used.
11Metadata::general()->prev('$the_prev_link_variable');
#Next Link
The next
method queues a <link rel="next" href="...">
tag. By default it binds to the $meta_link_next
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('meta_link_next', function (array $context) {
7 return 'the-url-here';
8});
9
10// Changing which variable is used.
11Metadata::general()->next('$the_next_link_variable');
#Self Link
The self
method queues a <link rel="self" href="...">
tag. By default it binds to the $current_full_url
variable.
1<?php
2
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4
5// Adjusting the returned variable.
6Metadata::resolve('current_full_url', function (array $context) {
7 return 'the-url-here';
8});
9
10// Changing which variable is used.
11Metadata::general()->self('$the_self_variable');