### Frontend Template Container Examples
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
These examples show the content of different frontend template containers, including author information, robots.txt, and ads.txt.
```text
/* TEAM */
Creator: nystudio107
URL: https://nystudio107.com/
Description: We do technology-based consulting, branding, design, and development. Making the web better one site at a time, with a focus on performance, usability & SEO
/* THANKS */
Craft CMS - https://craftcms.com
Pixel & Tonic - https://pixelandtonic.com
/* SITE */
Standards: HTML5, CSS3
Components: Craft CMS 3, Yii2, PHP, JavaScript, SEOmatic
```
```text
# robots.txt for http://localhost:8000/
sitemap: http://localhost:8000/sitemaps-1-sitemap.xml
sitemap: http://localhost:8000/es/sitemaps-1-sitemap.xml
# local - disallow all
User-agent: *
Disallow: /
```
```text
# ads.txt file for http://localhost:8000/
# More info: https://support.google.com/admanager/answer/7441288?hl=en
http://localhost:8000/,123,DIRECT
```
--------------------------------
### SEOmatic Plugin Configuration Example
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Example of how to configure SEOmatic globally across environments using `config/seomatic.php`. This allows for environment-specific settings like 'live', 'staging', or 'local'.
```php
// config/seomatic.php — multi-environment config
return [
'*' => [
'pluginName' => 'SEOmatic',
'renderEnabled' => true,
'sitemapsEnabled' => true,
'environment' => 'live', // 'live' | 'staging' | 'local'
'displayPreviewSidebar' => true,
'displayAnalysisSidebar' => true,
'devModeTitlePrefix' => '🚧 ',
'separatorChar' => '|',
'maxTitleLength' => 70,
'maxDescriptionLength' => 155,
],
'staging' => [
'environment' => 'staging',
],
'local' => [
'environment' => 'local',
],
];
```
--------------------------------
### Complete Pagination Example with SEOmatic
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/using/pagination.md
A full example demonstrating Craft CMS's `paginate` tag alongside SEOmatic's `paginate` helper for SEO-friendly pagination. Ensure `PAGEINFO` is correctly passed to the helper.
```twig
{% paginate craft.entries()
.section('blog')
.limit(10) as pageInfo, pageEntries %}
{% do seomatic.helper.paginate(pageInfo) %}
{% for entry in pageEntries %}
{{ entry.title }}
{{ entry.body }}
{% endfor %}
{% if pageInfo.prevUrl %}
Previous Page
{% endif %}
{% if pageInfo.nextUrl %}
Next Page
{% endif %}
```
--------------------------------
### Install SEOmatic via Composer and Craft CLI
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Install the SEOmatic plugin using Composer and then enable it via the Craft CLI. Ensure you are in your project's root directory.
```bash
cd /path/to/project
composer require nystudio107/craft-seomatic
php craft install/plugin seomatic
```
--------------------------------
### Install SEOmatic Plugin via Craft CMS CLI
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/README.md
After installing via Composer, install the SEOmatic plugin using the Craft CMS command-line interface.
```bash
./craft install/plugin seomatic
```
--------------------------------
### Headless SPA API - GraphQL
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Fetch meta containers using GraphQL for headless setups.
```APIDOC
## Headless SPA API — GraphQL
SEOmatic integrates with Craft CMS GraphQL for fully headless setups.
### Fetch Meta Containers
```graphql
# Fetch all meta containers for a URI (returns HTML strings for direct DOM injection)
{
seomatic(uri: "/blog/my-post") {
metaTitleContainer
metaTagContainer
metaLinkContainer
metaScriptContainer
metaJsonLdContainer
metaSiteVarsContainer
}
}
```
```
--------------------------------
### Meta Container API Response Example
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
This is an example of the JSON response structure when requesting all meta containers for a URI. It includes various meta tag types like title, tags, links, scripts, and JSON-LD.
```json
{
"MetaTitleContainer": "
[devMode] Craft3 | Homepage",
"MetaTagContainer": "",
"MetaLinkContainer": "",
"MetaScriptContainer": "",
"MetaJsonLdContainer": "",
"MetaSiteVarsContainer": "{\"siteName\":\"woof\",\"identity\":{\"siteType\":\"Organization\",\"siteSubType\":\"LocalBusiness\",\"siteSpecificType\":\"none\",\"computedType\":\"LocalBusiness\",\"genericName\":\"\",\"genericAlternateName\":\"\",\"genericDescription\":\"\",\"genericUrl\":\"$HOME\",\"genericImage\":null,\"genericImageWidth\":\"229\",\"genericImageHeight\":\"220\",\"genericImageIds\":[\"25\"],\"genericTelephone\":\"\",\"genericEmail\":\"\",\"genericStreetAddress\":\"\",\"genericAddressLocality\":\"\",\"genericAddressRegion\":\"\",\"genericPostalCode\":\"\",\"genericAddressCountry\":\"\",\"genericGeoLatitude\":\"\",\"genericGeoLongitude\":\"\",\"personGender\":\"Male\",\"personBirthPlace\":\"\",\"organizationDuns\":\"\",\"organizationFounder\":\"\",\"organizationFoundingDate\":\"\",\"organizationFoundingLocation\":\"\",\"organizationContactPoints\":\"\",\"corporationTickerSymbol\":\"\",\"localBusinessPriceRange\":\"$\",\"localBusinessOpeningHours\":[{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null}],\"restaurantServesCuisine\":\"\",\"restaurantMenuUrl\":\"\",\"restaurantReservationsUrl\":\"\"},\"creator\":{\"siteType\":\"Organization\",\"siteSubType\":\"LocalBusiness\",\"siteSpecificType\":\"none\",\"computedType\":\"LocalBusiness\",\"genericName\":\"\",\"genericAlternateName\":\"\",\"genericDescription\":\"\",\"genericUrl\":\"\",\"genericImage\":null,\"genericImageWidth\":\"1340\",\"genericImageHeight\":\"596\",\"genericImageIds\":[\"24\"],\"genericTelephone\":\"\",\"genericEmail\":\"\",\"genericStreetAddress\":\"\",\"genericAddressLocality\":\"\",\"genericAddressRegion\":\"\",\"genericPostalCode\":\"\",\"genericAddressCountry\":\"\",\"genericGeoLatitude\":\"\",\"genericGeoLongitude\":\"\",\"personGender\":\"Male\",\"personBirthPlace\":\"\",\"organizationDuns\":\"\",\"organizationFounder\":\"\",\"organizationFoundingDate\":\"\",\"organizationFoundingLocation\":\"\",\"organizationContactPoints\":\"\",\"corporationTickerSymbol\":\"\",\"localBusinessPriceRange\":\"$\",\"localBusinessOpeningHours\":[{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null}],\"restaurantServesCuisine\":\"\",\"restaurantMenuUrl\":\"\",\"restaurantReservationsUrl\":\"\"},\"twitterHandle\":\"\",\"facebookProfileId\":\"\",\"facebookAppId\":\"\",\"googleSiteVerification\":\"\",\"bingSiteVerification\":\"\",\"pinterestSiteVerification\":\"\",\"sameAsLinks\":{\"twitter\":{\"siteName\":\"Twitter\",\"handle\":\"twitter\",\"url\":\"\"},\"facebook\":{\"siteName\":\"Facebook\",\"handle\":\"facebook\",\"url\":\"\"},\"wikipedia\":{\"siteName\":\"Wikipedia\",\"handle\":\"wikipedia\",\"url\":\"\"},\"linkedin\":{\"siteName\":\"LinkedIn\",\"handle\":\"linkedin\",\"url\":\"\"},\"googleplus\":{\"siteName\":\"Google+\",\"handle\":\"googleplus\",\"url\":\"\"},\"youtube\":{\"siteName\":\"YouTube\",\"handle\":\"youtube\",\"url\":\"\"},\"instagram\":{\"siteName\":\"Instagram\",\"handle\":\"instagram\",\"url\":\"\"},\"pinterest\":{\"siteName\":\"Pinterest\",\"handle\":\"pinterest\",\"url\":\"\"},\"github\":{\"siteNam
```
--------------------------------
### Get Available Size Options
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/src/web/assets/dist/stats.html
Determines which size properties (rendered, gzip, brotli) are available based on the provided options object.
```javascript
const getAvailableSizeOptions = (options) => {
const availableSizeProperties = ["renderedLength"];
if (options.gzip) {
availableSizeProperties.push("gzipLength");
}
if (options.brotli) {
availableSizeProperties.push("brotliLength");
}
return availableSizeProperties;
};
```
--------------------------------
### Rendered Open Graph Images
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/using/tag-meta.md
Example of how multiple Open Graph image meta tags are rendered in HTML.
```html
```
--------------------------------
### Get All Meta Containers by URI
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
Retrieve all meta containers for a given URI. Supports filtering by site ID and returning results as an array.
```php
/actions/seomatic/meta-container/all-meta-containers/?uri=/
```
```php
/actions/seomatic/meta-container/all-meta-containers/?uri=/&siteId=2
```
```php
/actions/seomatic/meta-container/all-meta-containers/?uri=/&asArray=true
```
--------------------------------
### Get Same As URLs by Handle
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/using/helper-functions.md
Retrieves information about a 'Same As URLs' site based on its handle. The returned array contains the site's name, handle, URL, and account identifier.
```php
array (
'siteName' => string 'Twitter',
'handle' => string 'twitter',
'url' => string 'https://twitter.com/nystudio107',
'account' => string 'nystudio107'
)
```
--------------------------------
### Example Meta Container Data
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
This JSON object represents a full meta container, including site details, social media links, and various SEO-related settings.
```json
{
"siteType": "Organization",
"siteSubType": "LocalBusiness",
"siteSpecificType": "none",
"computedType": "LocalBusiness",
"genericName": "",
"genericAlternateName": "",
"genericDescription": "",
"genericUrl": "",
"genericImage": null,
"genericImageWidth": "1340",
"genericImageHeight": "596",
"genericImageIds": [
"24"
],
"genericTelephone": "",
"genericEmail": "",
"genericStreetAddress": "",
"genericAddressLocality": "",
"genericAddressRegion": "",
"genericPostalCode": "",
"genericAddressCountry": "",
"personGender": "Male",
"personBirthPlace": "",
"organizationDuns": "",
"organizationFounder": "",
"organizationFoundingDate": "",
"organizationFoundingLocation": "",
"organizationContactPoints": "",
"corporationTickerSymbol": "",
"localBusinessPriceRange": "$",
"localBusinessOpeningHours": [
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
}
],
"restaurantServesCuisine": "",
"restaurantMenuUrl": "",
"restaurantReservationsUrl": ""
},
"twitterHandle": "",
"facebookProfileId": "",
"facebookAppId": "",
"googleSiteVerification": "",
"bingSiteVerification": "",
"pinterestSiteVerification": "",
"sameAsLinks": {
"twitter": {
"siteName": "Twitter",
"handle": "twitter",
"url": ""
},
"facebook": {
"siteName": "Facebook",
"handle": "facebook",
"url": ""
},
"wikipedia": {
"siteName": "Wikipedia",
"handle": "wikipedia",
"url": ""
},
"linkedin": {
"siteName": "LinkedIn",
"handle": "linkedin",
"url": ""
},
"googleplus": {
"siteName": "Google+",
"handle": "googleplus",
"url": ""
},
"youtube": {
"siteName": "YouTube",
"handle": "youtube",
"url": ""
},
"instagram": {
"siteName": "Instagram",
"handle": "instagram",
"url": ""
},
"pinterest": {
"siteName": "Pinterest",
"handle": "pinterest",
"url": ""
},
"github": {
"siteName": "GitHub",
"handle": "github",
"url": ""
},
"vimeo": {
"siteName": "Vimeo",
"handle": "vimeo",
"url": ""
}
},
"siteLinksSearchTarget": "",
"siteLinksQueryInput": "",
"referrer": "no-referrer-when-downgrade",
"additionalSitemapUrls": [],
"additionalSitemapUrlsDateUpdated": null,
"additionalSitemaps": []
```
--------------------------------
### GraphQL Query with site handle
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Use the `site` handle parameter to specify which site's SEO data to retrieve in a multi-site Craft CMS setup.
```graphql
{
seomatic(uri: "/blog/my-post", site: "french") {
metaTitleContainer
metaTagContainer
}
}
```
--------------------------------
### Null Coalescing Operator (??) Example
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/using/empty-coalesce-operator.md
This example shows how the standard null coalescing operator (`??`) selects the first defined and non-null value. However, it will still use empty strings or arrays if they are the first available values.
```twig
{% set description = entry.description ??
category.description ??
global.description %}
```
--------------------------------
### Retrieve All Meta Containers
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
Fetches all meta containers for a given URI. This action can be filtered by `siteId` to target a specific site in a multi-site setup, or by setting `asArray=true` to return the data in an array format.
```APIDOC
## GET /actions/seomatic/meta-container/all-meta-containers
### Description
Retrieves all meta containers for a given URI.
### Method
GET
### Endpoint
/actions/seomatic/meta-container/all-meta-containers
### Parameters
#### Query Parameters
- **uri** (string) - Required - The URI to fetch meta containers for.
- **siteId** (integer) - Optional - The ID of the site to retrieve meta containers for.
- **asArray** (boolean) - Optional - If true, returns the data in an array format.
### Request Example
```bash
/actions/seomatic/meta-container/all-meta-containers/?uri=/
/actions/seomatic/meta-container/all-meta-containers/?uri=/&siteId=2
/actions/seomatic/meta-container/all-meta-containers/?uri=/&asArray=true
```
### Response
#### Success Response (200)
Returns a JSON object containing various meta containers (e.g., MetaTitleContainer, MetaTagContainer, MetaLinkContainer, MetaScriptContainer, MetaJsonLdContainer, MetaSiteVarsContainer) for the specified URI. The structure of the response may vary based on the `asArray` parameter.
#### Response Example (asArray=true)
```json
{
"MetaTitleContainer": {
"title": {
"title": "[devMode] Craft3 | Homepage"
}
},
"MetaTagContainer": {
"generator": {
"content": "SEOmatic",
"name": "generator"
},
"referrer": {
"content": "no-referrer-when-downgrade",
"name": "referrer"
},
"robots": {
"content": "all",
"name": "robots"
}
},
"MetaLinkContainer": {
"canonical": {
"href": "http://craft3.test/",
"rel": "canonical"
},
"author": {
"href": "/humans.txt",
"rel": "author",
"type": "text/plain"
},
"alternate": {
"href": "http://craft3.test/",
"hreflang": "es",
"rel": "alternate"
}
},
"MetaScriptContainer": [],
"MetaJsonLdContainer": {
"WebPage": {
"@context": "http://schema.org",
"@type": "WebPage",
"image": {
"@type": "ImageObject",
"height": "804",
"width": "1200"
},
"inLanguage": "en-us",
"mainEntityOfPage": "http://craft3.test/",
"name": "Homepage",
"url": "http://craft3.test/"
},
"BreadcrumbList": {
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"description": "Breadcrumbs list",
"itemListElement": [
{
"@type": "ListItem",
"name": "Homepage",
"item": "http://craft3.test/",
"position": 1
}
],
"name": "Breadcrumbs"
}
},
"MetaSiteVarsContainer": {
"siteName": "woof",
"identity": {
"siteType": "Organization",
"siteSubType": "LocalBusiness",
"siteSpecificType": "none",
"computedType": "LocalBusiness",
"genericName": "",
"genericAlternateName": "",
"genericDescription": "",
"genericUrl": "$HOME",
"genericImage": null,
"genericImageWidth": "229",
"genericImageHeight": "220",
"genericImageIds": [
"25"
],
"genericTelephone": "",
"genericEmail": "",
"genericStreetAddress": "",
"genericAddressLocality": "",
"genericAddressRegion": "",
"genericPostalCode": "",
"genericAddressCountry": "",
"genericGeoLatitude": "",
"genericGeoLongitude": "",
"personGender": "Male",
"personBirthPlace": "",
"organizationDuns": "",
"organizationFounder": "",
"organizationFoundingDate": "",
"organizationFoundingLocation": "",
"organizationContactPoints": "",
"corporationTickerSymbol": "",
"localBusinessPriceRange": "$",
"localBusinessOpeningHours": [
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
},
{
"open": null,
"close": null
}
],
"restaurantServesCuisine": "",
"restaurantMenuUrl": "",
"restaurantReservationsUrl": ""
},
"creator": {
"siteName": "GitHub",
"handle": "github",
"url": ""
},
"vimeo": {
"siteName": "Vimeo",
"handle": "vimeo",
"url": ""
},
"siteLinksSearchTarget": "",
"siteLinksQueryInput": "",
"referrer": "no-referrer-when-downgrade",
"additionalSitemapUrls": [],
"additionalSitemapUrlsDateUpdated": null,
"additionalSitemaps": []
}
}
```
```
--------------------------------
### Example: Excluding a script
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/using/script-meta.md
Demonstrates how to exclude a specific script, like Google Analytics, from being included on a page.
```APIDOC
## Example: Excluding a script
Don’t include the Google Analytics script on the page:
```twig
{% do seomatic.script.get("googleAnalytics").include(false) %}
```
```
--------------------------------
### Get All Meta Containers
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
Retrieve all meta containers for a given URI. This includes render-ready meta tags for title, general meta tags, links, scripts, and JSON-LD.
```APIDOC
## GET /actions/seomatic/meta-container/all-meta-containers
### Description
Retrieves all meta containers for a given URI, including render-ready meta tags.
### Method
GET
### Endpoint
/actions/seomatic/meta-container/all-meta-containers/
### Parameters
#### Query Parameters
- **uri** (string) - Required - The URI path to obtain the meta information from.
### Response
#### Success Response (200)
- **MetaTitleContainer** (string) - Rendered meta title tag.
- **MetaTagContainer** (string) - Rendered general meta tags (e.g., generator, robots).
- **MetaLinkContainer** (string) - Rendered meta link tags (e.g., canonical, alternate).
- **MetaScriptContainer** (string) - Rendered meta script tags.
- **MetaJsonLdContainer** (string) - Rendered JSON-LD script tags.
- **MetaSiteVarsContainer** (string) - JSON string containing site variables.
### Response Example
```json
{
"MetaTitleContainer": "[devMode] Craft3 | Homepage",
"MetaTagContainer": "",
"MetaLinkContainer": "",
"MetaScriptContainer": "",
"MetaJsonLdContainer": "",
"MetaSiteVarsContainer": "{\"siteName\":\"woof\",\"identity\":{\"siteType\":\"Organization\",\"siteSubType\":\"LocalBusiness\",\"siteSpecificType\":\"none\",\"computedType\":\"LocalBusiness\",\"genericName\":\"\",\"genericAlternateName\":\"\",\"genericDescription\":\"\",\"genericUrl\":\"$HOME\",\"genericImage\":null,\"genericImageWidth\":\"229\",\"genericImageHeight\":\"220\",\"genericImageIds\":[\"25\"],\"genericTelephone\":\"\",\"genericEmail\":\"\",\"genericStreetAddress\":\"\",\"genericAddressLocality\":\"\",\"genericAddressRegion\":\"\",\"genericPostalCode\":\"\",\"genericAddressCountry\":\"\",\"genericGeoLatitude\":\"\",\"genericGeoLongitude\":\"\",\"personGender\":\"Male\",\"personBirthPlace\":\"\",\"organizationDuns\":\"\",\"organizationFounder\":\"\",\"organizationFoundingDate\":\"\",\"organizationFoundingLocation\":\"\",\"organizationContactPoints\":\"\",\"corporationTickerSymbol\":\"\",\"localBusinessPriceRange\":\"$\",\"localBusinessOpeningHours\":[{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null}],\"restaurantServesCuisine\":\"\",\"restaurantMenuUrl\":\"\",\"restaurantReservationsUrl\":\"\"},\"creator\":{\"siteType\":\"Organization\",\"siteSubType\":\"LocalBusiness\",\"siteSpecificType\":\"none\",\"computedType\":\"LocalBusiness\",\"genericName\":\"\",\"genericAlternateName\":\"\",\"genericDescription\":\"\",\"genericUrl\":\"\",\"genericImage\":null,\"genericImageWidth\":\"1340\",\"genericImageHeight\":\"596\",\"genericImageIds\":[\"24\"],\"genericTelephone\":\"\",\"genericEmail\":\"\",\"genericStreetAddress\":\"\",\"genericAddressLocality\":\"\",\"genericAddressRegion\":\"\",\"genericPostalCode\":\"\",\"genericAddressCountry\":\"\",\"genericGeoLatitude\":\"\",\"genericGeoLongitude\":\"\",\"personGender\":\"Male\",\"personBirthPlace\":\"\",\"organizationDuns\":\"\",\"organizationFounder\":\"\",\"organizationFoundingDate\":\"\",\"organizationFoundingLocation\":\"\",\"organizationContactPoints\":\"\",\"corporationTickerSymbol\":\"\",\"localBusinessPriceRange\":\"$\",\"localBusinessOpeningHours\":[{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null},{\"open\":null,\"close\":null}],\"restaurantServesCuisine\":\"\",\"restaurantMenuUrl\":\"\",\"restaurantReservationsUrl\":\"\"},\"twitterHandle\":\"\",\"facebookProfileId\":\"\",\"facebookAppId\":\"\",\"googleSiteVerification\":\"\",\"bingSiteVerification\":\"\",\"pinterestSiteVerification\":\"\",\"sameAsLinks\":{\"twitter\":{\"siteName\":\"Twitter\",\"handle\":\"twitter\",\"url\":\"\"},\"facebook\":{\"siteName\":\"Facebook\",\"handle\":\"facebook\",\"url\":\"\"},\"wikipedia\":{\"siteName\":\"Wikipedia\",\"handle\":\"wikipedia\",\"url\":\"\"},\"linkedin\":{\"siteName\":\"LinkedIn\",\"handle\":\"linkedin\",\"url\":\"\"},\"googleplus\":{\"siteName\":\"Google+\",\"handle\":\"googleplus\",\"url\":\"\"},\"youtube\":{\"siteName\":\"YouTube\",\"handle\":\"youtube\",\"url\":\"\"},\"instagram\":{\"siteName\":\"Instagram\",\"handle\":\"instagram\",\"url\":\"\"},\"pinterest\":{\"siteName\":\"Pinterest\",\"handle\":\"pinterest\",\"url\":\"\"},\"github\":{\"siteNam
```
--------------------------------
### Example JSON Output for Schema.org Sub-types
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
This JSON structure represents the output for a specific sub-type path query, showing nested Schema.org types.
```json
{
"AdvertiserContentArticle": "AdvertiserContentArticle",
"NewsArticle": {
"AnalysisNewsArticle": "AnalysisNewsArticle",
"BackgroundNewsArticle": "BackgroundNewsArticle",
"OpinionNewsArticle": "OpinionNewsArticle",
"ReportageNewsArticle": "ReportageNewsArticle",
"ReviewNewsArticle": "ReviewNewsArticle"
},
"Report": "Report",
"SatiricalArticle": "SatiricalArticle",
"ScholarlyArticle": {
"MedicalScholarlyArticle": "MedicalScholarlyArticle"
},
"SocialMediaPosting": {
"BlogPosting": {
"LiveBlogPosting": "LiveBlogPosting"
},
"DiscussionForumPosting": "DiscussionForumPosting"
},
"TechArticle": {
"APIReference": "APIReference"
}
}
```
--------------------------------
### GraphQL Queries for SEOmatic Data
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Examples of GraphQL queries to fetch SEO meta information for different scenarios, including multi-site configurations, structured arrays, environment overrides, and piggybacking on entry queries.
```APIDOC
## GraphQL Queries
### With siteId for multi-site
```graphql
{
seomatic(uri: "/blog/my-post", siteId: 2) {
metaTitleContainer
metaTagContainer
}
}
```
### With site handle for multi-site
```graphql
{
seomatic(uri: "/blog/my-post", site: "french") {
metaTitleContainer
metaTagContainer
}
}
```
### Return structured arrays instead of HTML
```graphql
{
seomatic(uri: "/blog/my-post", asArray: true) {
metaTitleContainer
metaTagContainer
metaLinkContainer
metaJsonLdContainer
}
}
```
### Override the environment
```graphql
{
seomatic(uri: "/", environment: staging) {
metaTitleContainer
metaTagContainer
}
}
```
### Piggyback on an entries query
```graphql
{
entry(section: "blog", slug: "my-post") {
id
title
seomatic(asArray: true) {
metaTitleContainer
metaTagContainer
metaLinkContainer
metaJsonLdContainer
}
}
}
```
### Frontend templates (robots.txt, humans.txt, ads.txt, security.txt)
```graphql
{
seomatic {
frontendTemplates(type: robots) {
filename
contents
}
}
}
```
### Sitemap index
```graphql
{
seomatic {
sitemapIndexes(siteId: 1) {
filename
contents
}
}
}
```
### Specific sitemaps
```graphql
{
seomatic {
sitemaps(sourceBundleType: "section", sourceBundleHandle: "blog") {
filename
contents
}
}
}
```
### XSL sitemap stylesheet
```graphql
{
seomatic {
sitemapStyles {
filename
contents
}
}
}
```
```
--------------------------------
### Get All Meta Containers for a URI
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
Use this endpoint to fetch all meta containers for a specific URI. Ensure anonymous access is enabled in SEOmatic plugin settings if needed.
```twig
/actions/seomatic/meta-container/all-meta-containers/?uri=/
```
--------------------------------
### Install SEOmatic Plugin via Composer
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/README.md
Use Composer to require the SEOmatic plugin in your Craft CMS project. Navigate to your project directory first.
```bash
cd /path/to/project
composer require nystudio107/craft-seomatic
```
--------------------------------
### Fetch Meta Containers via GraphQL API
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Integrate SEOmatic with Craft CMS GraphQL to fetch meta containers for headless setups. This returns HTML strings suitable for direct DOM injection.
```graphql
# Fetch all meta containers for a URI (returns HTML strings for direct DOM injection)
{
seomatic(uri: "/blog/my-post") {
metaTitleContainer
metaTagContainer
metaLinkContainer
metaScriptContainer
metaJsonLdContainer
metaSiteVarsContainer
}
}
```
--------------------------------
### PHP Events for SEOmatic Integrations
Source: https://context7.com/nystudio107/craft-seomatic/llms.txt
Examples of how to use PHP event hooks to react to SEOmatic lifecycle events, allowing for custom meta injection, container suppression, cache invalidation, sitemap filtering, and more.
```APIDOC
## PHP Events
### Inject custom dynamic meta at render time
```php
use nystudio107\seomatic\events\AddDynamicMetaEvent;
use nystudio107\seomatic\helpers\DynamicMeta;
use nystudio107\seomatic\Seomatic;
use yii\base\Event;
Event::on(
DynamicMeta::class,
DynamicMeta::EVENT_ADD_DYNAMIC_META,
function(AddDynamicMetaEvent $event) {
Seomatic::$seomaticVariable->meta->seoDescription =
"This description overrides any others!";
}
);
```
### Prevent a specific container from being included
```php
use nystudio107\seomatic\events\IncludeContainerEvent;
use nystudio107\seomatic\base\Container;
Event::on(
Container::class,
Container::EVENT_INCLUDE_CONTAINER,
function(IncludeContainerEvent $event) {
// e.g. $event->include = false; to suppress the container
}
);
```
### React to cache invalidation
```php
use nystudio107\seomatic\events\InvalidateContainerCachesEvent;
use nystudio107\seomatic\services\MetaContainers;
Event::on(
MetaContainers::class,
MetaContainers::EVENT_INVALIDATE_CONTAINER_CACHES,
function(InvalidateContainerCachesEvent $event) {
// Perform additional cache busting operations
}
);
```
### Filter which entries appear in a sitemap
```php
use nystudio107\seomatic\events\IncludeSitemapEntryEvent;
use nystudio107\seomatic\helpers\Sitemap;
Event::on(
Sitemap::class,
Sitemap::EVENT_INCLUDE_SITEMAP_ENTRY,
function(IncludeSitemapEntryEvent $event) {
// $event->include = false; to exclude this entry from the sitemap
}
);
```
### Modify the element query used to build a sitemap
```php
use nystudio107\seomatic\events\ModifySitemapQueryEvent;
Event::on(
Sitemap::class,
Sitemap::EVENT_MODIFY_SITEMAP_QUERY,
function(ModifySitemapQueryEvent $event) {
$event->query->limit(100); // limit entries in this sitemap
}
);
```
### Register additional custom URLs in a sitemap
```php
use nystudio107\seomatic\events\RegisterSitemapUrlsEvent;
use nystudio107\seomatic\models\SitemapCustomTemplate;
Event::on(
SitemapCustomTemplate::class,
SitemapCustomTemplate::EVENT_REGISTER_SITEMAP_URLS,
function(RegisterSitemapUrlsEvent $event) {
$event->sitemaps[] = [
'loc' => 'https://example.com/custom-page',
'changefreq' => 'weekly',
'priority' => '0.5',
'lastmod' => date('Y-m-d'),
];
}
);
```
### Register additional sitemap files in the sitemap index
```php
use nystudio107\seomatic\events\RegisterSitemapsEvent;
use nystudio107\seomatic\models\SitemapIndexTemplate;
Event::on(
SitemapIndexTemplate::class,
SitemapIndexTemplate::EVENT_REGISTER_SITEMAPS,
function(RegisterSitemapsEvent $event) {
$event->sitemaps[] = [
'loc' => 'https://example.com/custom-sitemap.xml',
'lastmod' => date('Y-m-d'),
];
}
);
```
### Register a custom SeoElement type
```php
use nystudio107\seomatic\services\SeoElements;
use craft\events\RegisterComponentTypesEvent;
Event::on(
SeoElements::class,
SeoElements::EVENT_REGISTER_SEO_ELEMENT_TYPES,
function(RegisterComponentTypesEvent $event) {
$event->types[] = MyCustomSeoElement::class;
}
);
```
```
--------------------------------
### Retrieve Frontend Templates Container
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/advanced.md
Use this endpoint to get the Frontend Templates container for a specific URI. The response is in JSON format. Add `&asArray=true` to receive the data as an array.
```bash
/actions/seomatic/meta-container/frontend-template-container/?uri=/
```
```json
{
"FrontendTemplateContainer": "[{{\"humans\":\"/* TEAM */\\n\\nCreator: nystudio107\\nURL: https://nystudio107.com/\\nDescription: We do technology-based consulting, branding, design, and development. Making the web better one site at a time, with a focus on performance, usability & SEO\\n\\n/* THANKS */\\n\\nCraft CMS - https://craftcms.com\\nPixel & Tonic - https://pixelandtonic.com\\n\\n/* SITE */\\n\\nStandards: HTML5, CSS3\\nComponents: Craft CMS 3, Yii2, PHP, JavaScript, SEOmatic\"}},{{\"robots\":\"# robots.txt for http://localhost:8000/\\n\\nsitemap: http://localhost:8000/sitemaps-1-sitemap.xml\\nsitemap: http://localhost:8000/es/sitemaps-1-sitemap.xml\\n\\n# local - disallow all\\n\\nUser-agent: *\\nDisallow: /\\n\\n\"}},{{\"ads\":\"# ads.txt file for http://localhost:8000/\\n# More info: https://support.google.com/admanager/answer/7441288?hl=en\\nhttp://localhost:8000/,123,DIRECT\\n\"}}]"
```
--------------------------------
### Configure Google AMP Analytics
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/google-amp.md
Integrate Google AMP Analytics into your AMP templates. This example assumes you are using `gtag` and utilizes SEOmatic's empty coalesce operator for the analytics ID.
```twig
{% set script = seomatic.script.get('gtag') %}
{% set analyticsId = script.vars.googleAnalyticsId.value ??? '' %}
```
--------------------------------
### Get Sitemap Index URL
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/docs/docs/using/helper-functions.md
Retrieves the URL to the sitemap index for a specified site ID. This is useful for linking to the sitemap of a particular site within a multi-site installation.
```php
seomatic.helper.sitemapIndexForSiteId(SITE_ID)
```
--------------------------------
### Initialize Chart Drawing
Source: https://github.com/nystudio107/craft-seomatic/blob/develop-v5/src/web/assets/dist/stats.html
Sets up the main drawing function for the chart, including context providers and main component rendering. This is the entry point for rendering the chart.
```javascript
const drawChart = (parentNode, data, layout, width, height) => {
const rawHierarchy = data.hierarchy;
const availableSizeProperties = Object.keys(rawHierarchy[0].children[0]);
const nodeIdsCache = new Map();
const nodeSizesCache = new Map();
const nodeIds = rawHierarchy.reduce((acc, node) => {
acc.push(node.uid);
return acc;
}, []);
rawHierarchy.forEach(nodeData => {
nodeData.children.forEach(child => {
nodeIdsCache.set(child, child.uid);
});
});
rawHierarchy.forEach(nodeData => {
const sizes = {};
if (nodeData.children.length > 0) { for (const sizeKey of availableSizeProperties) { sizes[sizeKey] = nodeData.children.reduce((acc, child) => getModuleSize(child, sizeKey) + acc, 0); } } else { for (const sizeKey of availableSizeProperties) { sizes[sizeKey] = (_a = data.nodeParts[nodeData.uid][sizeKey]) !== null && _a !== void 0 ? _a : 0; } } nodeSizesCache.set(nodeData, sizes);
});
console.timeEnd("rawHierarchy eachAfter cache");
const getModuleIds = (node) => nodeIdsCache.get(node);
console.time("color");
const getModuleColor = createRainbowColor(rawHierarchy);
console.timeEnd("color");
D$1(u$1(StaticContext.Provider, { value: { data, availableSizeProperties, width, height, getModuleSize, getModuleIds, getModuleColor, rawHierarchy, layout, }, children: u$1(Main, {}) }), parentNode);
};
exports.StaticContext = StaticContext;
exports.default = drawChart;
Object.defineProperty(exports, '\u005C\u005C__esModule', { value: true });
return exports;
})({});
/*-->*/
/*