-
-
Notifications
You must be signed in to change notification settings - Fork 45
08. Main Entity of Page Microdata
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 will automatically generate Main Entity of Page JSON-LD microdata for Template and Entry SEO Meta.
The Main Entity of Page is a more specific, additional type of information that describes the page. This additional JSON-LD structured data entity will be added to your page, more specifically describing the page's content. It is accessible via the seomaticMainEntityOfPage
Twig variable.
If an SEOmatic FieldType is attached to a Craft Commerce Product, SEOmatic will automatically extrapolate information from the Product. Otherwise, you can choose your own Main Entity of Page in the SEOmatic FieldType.
SEOmatic fills in the basic information for whatever schema type you set as the Main Entity of Page, but since this is just a Twig array, you can alter it as you see fit, and whatever changes you make will be reflected in the JSON-LD that SEOmatic renders via the {% hook 'seomaticRender' %}
Because of the way that Twig handles arrays, you must include every field in the array when doing a set
or merge
, otherwise the fields you exclude will not exist.
Here's an example of how you might add a startDate
to an Event
schema type:
{% if seomaticMainEntityOfPage is defined %}
{% set eventStartDate = entry.eventDate %}
{% set seomaticMainEntityOfPage = seomaticMainEntityOfPage | merge({'startDate': eventStartDate }) %}
{% endif %}
Note that Event
schema types require startDate
and location
to be set, which SEOmatic is unable to automatically fill in for you. Additionally, you may want to add more information to any of the schema types used for Main Entity of Page to give search engines more information to add to their knowledge graph.
Google recommends the use of JSON-LD Structured Data for Subscription and paywalled content. This is strongly encouraged, so that you are not errantly punished for violating Google's cloaking policies or guidelines.
Whether your content is available only after a free registration process, or it's available only to people who subscribe to your website, it's recommended that you use this markup to help Google understand your content.
SEOmatic makes it easy to add this to your MainEntityOfPage
using markup such as this in your Twig template:
{% if seomaticMainEntityOfPage is defined %}
{% set seomaticMainEntityOfPage = seomaticMainEntityOfPage | merge({
'isAccessibleForFree': 'False',
'hasPart': {
'type': 'WebPageElement',
'isAccessibleForFree': 'False',
'cssSelector': '.paywall',
}
}) %}
{% endif %}
Where the .paywall
class is whatever your CSS selector is for blocking access to your content. If you have more then one, you'd do something like:
{% if seomaticMainEntityOfPage is defined %}
{% set seomaticMainEntityOfPage = seomaticMainEntityOfPage | merge({
'isAccessibleForFree': 'False',
'hasPart': [
{
'type': 'WebPageElement',
'isAccessibleForFree': 'False',
'cssSelector': '.paywall',
},
{
'type': 'WebPageElement',
'isAccessibleForFree': 'False',
'cssSelector': '#blocksContent',
}
]
}) %}
{% endif %}
For more information, see Googe's support article Subscription and paywalled content.