1

With SEOmatic I want to be able to dynamically change the type of my mainEntity, which defaults to "Webpage" and in some cases I want to change it to "Event"

In an older project I did this:

{% do seomatic.jsonLd.get('mainEntityOfPage').type('Event') %}

But if I dump the mainEntity again, nothing has changed:

{% dd seomatic.jsonLd.get('mainEntityOfPage') %}

It's still a nystudio107\seomatic\models\jsonld\WebPage#1

How can I achieve this?

I'm using Craft 3.4.30 with Seomatic 3.3.35

1 Answer 1

3

So you can't just change the type of the mainEntityOfPage because there's a unique PHP class for each schema.org type.

What I would typically recommend here is that you set up the mappings via Content SEO (which lets you set up a different mainEntityOfPage per entry type) or you use the SEO Settings field to allow for per-entry changing of the mainEntityOfPage.

But if you really want to do it dynamically via Twig, you can. You just need to create a new object.

{% do seomatic.jsonLd.create({
    'key': 'mainEntityOfPage',
    'type': 'Whatever',
{# fill in other properties here #}
}) %}
1
  • aaah, providing the key does the trick. thanks! Mar 18, 2021 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.