Site Essentials for Statamic

Site Essentials for Statamic

Overview

Site Essentials for Statamic provides a robust metadata management system, easing the creation and management of a wide-variety of HTML title, meta, and link tags.

The metadata management system can be used for a wide variety of scenarios, including developing a customized SEO solution for sites, easily adding pagination link tags, simplifying your front-end templates, and more. While the metadata management can be used to develop an SEO solution for your site it does not provide a default UI for managing metadata, nor does it provided specialized/targeted features for SEO management, reporting, and strategy.

If you're looking for a more SEO-focused way to let your client's manage metadata information, you may consider checking out the Statamic Marketplace SEO category: https://statamic.com/addons/tags/seo. You are free to use any third-party addon in combination with the metadata management system.

#Registering Metadata Tags

Metadata information is managed from your site's backend code, primarily by interacting with the Metadata facade, typically within your site's AppServiceProvider. The metadata manager utilizes a "builder" concept, allowing you to chain multiple calls for a specific category of metadata information.

For example, the following would queue the many different meta and link tags to be generated for you automatically:

1<?php
2 
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4 
5Metadata::general()->charset()
6 ->viewport()
7 ->title()
8 ->description()
9 ->keywords();
10 
11Metadata::openGraph()->title()
12 ->description()
13 ->url();

The metadata manager would create all of the associated meta/link tags for you automatically. If it is not able to find the data to populate the tags, they will not be included in the final output.

#Registering Third-party Metadata Providers

The metadata manager also supports the concept of "metadata providers." These providers provide a simple way for external code to register multiple meta tags with Site Essential's metadata manager.

Metadata providers are added by using the addProviders method on the Metadata facade:

1<?php
2 
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4 
5Metadata::addProviders([
6 \Stillat\SocialMediaImageKit\Metadata\MetadataProvider::class,
7 \Stillat\StatamicSiteEssentials\Metadata\EssentialMetadataProvider::class,
8]);

Depending on the third-party providing the metadata provider, you will often no longer need to use additional specific tags to output their required metadata.

#Front-end Templating

In order for meta and link tags to appear in the output of your templates, you will need to use the se_meta Antlers tag. You should remove all hardcoded meta/link tags that you will be managing using the metadata builders so duplicates do not appear.

The simplest way to utilize the tag is like so:

1<!doctype html>
2<html>
3 <head>
4 {{ se_meta /}}
5 </head>
6</html>

#Pagination Links

If you are rendering a paginated list and would like to easily add pagination link tags, you can use the se_meta:paginate tag:

1{{ collection:blog paginate="5" as="items" }}
2 
3 {{# Add the current pagination links to metadata manager. #}}
4 {{ se_meta:paginate /}}
5{{ /collection:blog }}

#Integrating Third-Party Addons

If you are using a third-party addon and would like that addon's generated metadata to take priority over the meta/link tags generated by the se_meta tag, you can use the se_meta tag as a tag pair. You can output the additional meta/link tags within the tag pair:

1<!doctype html>
2<html>
3 <head>
4 {{ se_meta }}
5 {{ if {installed:statamic/seo-pro} }}
6 {{ seo_pro:meta }}
7 {{ /if }}
8 {{ /se_meta }}
9 </head>
10</html>

The metadata manager will parse the contents that appear within the tag pair, and remove any meta/link tags it generated that will conflict within. The meta/link tags that appear last within the tag's contents will take priority.

If you are using SEO Pro, you can use the seoPro helper method on the Metadata facade to achieve the same end result:

1<?php
2 
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4 
5Metadata::withDefaults()->seoPro();

#Registering Default Metadata

In the previous code sample, we saw a call to the withDefaults method. This method will register a number of common metadata entries for us. Specifically, it is equivalent to the following:

1<?php
2 
3use Stillat\StatamicSiteEssentials\Support\Facades\Metadata;
4 
5Metadata::general()
6 ->charset()
7 ->xUaCompatible()
8 ->viewport()
9 ->title()
10 ->description()
11 ->keywords()
12 ->localeAlternate();
13 
14Metadata::twitterX()->all();
15 
16Metadata::openGraph()
17 ->title()
18 ->description()
19 ->type()
20 ->url()
21 ->siteName()
22 ->locale()
23 ->localeAlternate();

#Automatic noindex, nofollow

By default the metadata manager will add the <meta name="robots" content="noindex, nofollow"> tag to all pages when the site is not running in production mode. This behavior can be changed by modifying guard_index_follow configuration value within the config/site_essentials/metadata.php file:

In config/site_essentials/metadata.php

1<?php
2 
3return [
4 
5 /*
6 |--------------------------------------------------------------------------
7 | Guard Index Follow
8 |--------------------------------------------------------------------------
9 |
10 | When set to true <meta name="robots" content="noindex, nofollow">
11 | will be added to the <head> of the page when the current user
12 | for environments that are not the production environment.
13 |
14 */
15 
16 'guard_index_follow' => true,
17 
18 // ...
19 
20];

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.