-
-
Notifications
You must be signed in to change notification settings - Fork 45
16. SEOmatic Twig Variables
This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons.
The Craft CMS 3.x version of this plugin can be found here: craft-seomatic and can also be installed via the Craft Plugin Store in the Craft CP.
SEOmatic populates your templates with the following global variables for Site Meta:
seomaticSiteMeta.siteSeoName
seomaticSiteMeta.siteSeoTitle
seomaticSiteMeta.siteSeoDescription
seomaticSiteMeta.siteSeoKeywords
seomaticSiteMeta.siteSeoImage
seomaticSiteMeta.siteOwnerType
All of the variables are from your SEO Site Meta settings, and will be the same for every template rendered. They are for the most part very similar to your SEO Meta variables, but they do not change from template to template: they are site-wide.
Mostly, you won't need to change them in your Twig templates, but it can be useful to reference or output them. These work like any other Twig variables; you can output them by doing:
{{ seomaticSiteMeta.siteSeoName }}
You can also change these variables the same way you change the "Dynamic Twig SEO Meta" (using Twig set
and merge
), but in practice they typically will just be set in the SEOmatic SEO Site Meta settings page in the Admin CP.
SEOmatic also automatically strips HTML/PHP tags from the variables, and translates HTML entities to ensure that they are properly encoded.
SEOmatic populates your templates with an array of Site Identity variables; see the Rendered Identity Microdata section for a complete listing of them. All of the variables are from your Site Identity settings, and will be the same for every template rendered.
Mostly, you won't need to change them in your Twig templates, but it can be useful to reference or output them. These work like any other Twig variables; you can output them by doing:
{{ seomaticIdentity.name }}
You can also change these variables the same way you change the "Dynamic Twig SEO Meta" (using Twig set
and merge
), but in practice they typically will just be set in the SEOmatic Site Identity settings page in the Admin CP.
Because the seomaticIdentity
array is directly translated into JSON-LD, you can manipulate it via Twig to modify or add to the JSON-LD. For example, let's say you want to add a Brand to your Corporation-type Identity JSON-LD:
{% set myBrand = {
type: "Brand",
name: "Brad's for Men",
description: "Brad Bell's musky essence will intoxicate you.",
url: "http://bradsformen.com",
logo: "http://bradsformen.com/logo.png",
image: "http://bradsformen.com/lifestyle.jpg",
} %}
{% set seomaticIdentity = seomaticIdentity | merge({'brand': myBrand }) %}
SEOmatic also automatically strips HTML/PHP tags from the variables, and translates HTML entities to ensure that they are properly encoded.
The email
variable is ordinal-encoded to obfuscate it. For instance, [email protected]
becomes:
info@nystudio107.com
SEOmatic populates your templates with the following global variables for Social Media:
seomaticSocial.twitterHandle
seomaticSocial.facebookHandle
seomaticSocial.facebookProfileId
seomaticSocial.linkedInHandle
seomaticSocial.googlePlusHandle
seomaticSocial.googleSiteVerification
seomaticSocial.youtubeHandle
seomaticSocial.instagramHandle
seomaticSocial.pinterestHandle
All of the variables are from your Social Media settings, and will be the same for every template rendered.
Mostly, you won't need to change them in your Twig templates, but it can be useful to reference or output them. These work like any other Twig variables; you can output them by doing:
{{ seomaticSocial.twitterHandle }}
You can also change these variables the same way you change the "Dynamic Twig SEO Meta" (using Twig set
and merge
), but in practice they typically will just be set in the SEOmatic Social Media settings page in the Admin CP.
SEOmatic also automatically strips HTML/PHP tags from the variables, and translates HTML entities to ensure that they are properly encoded.
SEOmatic populates your templates with an array of Site Creator variables; see the Rendered WebSite Microdata section for a complete listing of them. All of the variables are from your Site Creator settings, and will be the same for every template rendered.
Mostly, you won't need to change them in your Twig templates, but it can be useful to reference or output them. These work like any other Twig variables; you can output them by doing:
{{ seomaticCreator.name }}
You can also change these variables the same way you change the "Dynamic Twig SEO Meta" (using Twig set
and merge
), but in practice they typically will just be set in the SEOmatic Site Creator settings page in the Admin CP.
Because the seomaticCreator
array is directly translated into JSON-LD, you can manipulate it via Twig to modify or add to the JSON-LD. For example, let's say you want to add an affiliation
to your Person-type Creator JSON-LD:
{% set myAffiliation = {
type: "Organization",
name: "nystudio107",
description: "Impeccable design married with precision craftsmanship.",
url: "http://nystudio107.com",
} %}
{% set seomaticCreator = seomaticCreator | merge({'affiliation': myAffiliation }) %}
SEOmatic also automatically strips HTML/PHP tags from the variables, and translates HTML entities to ensure that they are properly encoded.
The email
variable is ordinal-encoded to obfuscate it. For instance, [email protected]
becomes:
info@nystudio107.com
SEOmatic populates your templates with the following "helper" variables for that you can use in your templates:
seomaticHelper.twitterUrl
seomaticHelper.facebookUrl
seomaticHelper.googlePlusUrl
seomaticHelper.linkedInUrl
seomaticHelper.youtubeUrl,
seomaticHelper.youtubeChannelUrl
seomaticHelper.instagramUrl
seomaticHelper.pinterestUrl
seomaticHelper.githubUrl
seomaticHelper.vimeoUrl
seomaticHelper.wikipediaUrl
seomaticHelper.ownerGoogleSiteVerification
seomaticHelper.ownerBingSiteVerification
seomaticHelper.ownerGoogleAnalyticsUID
seomaticHelper.ownerGoogleTagManagerID
seomaticHelper.googleAnalyticsSendPageview
seomaticHelper.googleAnalyticsAdvertising
seomaticHelper.googleAnalyticsEcommerce
seomaticHelper.googleAnalyticsEEcommerce
seomaticHelper.googleAnalyticsLinkAttribution
seomaticHelper.googleAnalyticsLinker
seomaticHelper.googleAnalyticsAnonymizeIp
seomaticHelper.ownerCopyrightNotice
seomaticHelper.ownerAddressString
seomaticHelper.ownerAddressHtml
seomaticHelper.ownerMapUrl
seomaticHelper.creatorCopyrightNotice
seomaticHelper.creatorAddressString
seomaticHelper.creatorAddressHtml
seomaticHelper.creatorMapUrl