Silverstripe Version: SS5
Question:
I’m using the SilverStripe SEO module GitHub - HelloBetterLTD/seo: SEO plugin SilverStripe · GitHub
Am having trouble using structured data and wondering if anyone else has any pointers?
The following basic .yml config works
---
Name: my-seo-structured
After: '#seo-structured'
---
App\Web\ProductPage:
schema_type: 'WebPage'
schema:
name: 'MetaTitle'
description: 'MetaDescription'
url: 'AbsoluteLink'
but I can’t work out how to add more to the schema, eg. I’d expect the following to work, but it doesn’t
App\Web\ProductPage:
schema_type: 'WebPage'
schema:
name: 'MetaTitle'
description: 'MetaDescription'
url: 'AbsoluteLink'
isPartOf:
'@type': 'WebSite'
'name': 'Website name'
'url': 'AbsoluteBaseURL'
Same with trying to add breadcrumbs or anything else more than 1 level deep.
Any tips would be most welcome!
Tim
2
If you can bump to CMS 6, you could look at this module:
Something I built just last week in fact to make the job nice and easy
1 Like
managed to get this working using php functions in the end.
Example .yml config:
App\Web\ProductPage:
schema_type: 'WebPage'
schema:
name: 'MetaTitle'
description: 'MetaDescription'
dateCreated: Created
dateModified: LastEdited
url: 'AbsoluteLink'
image: 'ImageURL'
thumbnailUrl: 'ImageURL'
breadcrumb: 'getSchemaBreadcrumb'
mainEntity: 'getSchemaMainEntity'
Then in ProductPage.php:
public function getSchemaMainEntity() {
$site_config = SiteConfig::current_site_config();
return [
...$this->getSchemaTypeAndArea($this),
'name' => $this->Title,
'url' => $this->AbsoluteLink(),
'description' => $this->getSchemaDescription(),
'category' => $this->getSchemaCategory(),
'additionalType' => $this->Parent()->Title,
'image' => $this->ImageURL(),
'provider' => [
'@type' => 'LocalBusiness',
'name' => $this->getSchemaSiteTitle(),
'url' => $this->getSchemaBaseURL(),
'image' => $this->getSchemaLogoURL(),
'logo' => $this->getSchemaLogoURL(),
'address' => $site_config->Address,
'telephone' => $site_config->Phone
],
'offers' => $this->getSchemaOffers(),
'audience' => $this->dbObject('Audience')->Plain(),
'isRelatedTo' => $this->getSchemaRelatedTo(),
'aggregateRating' => $this->getSchemaAggregateRating(),
'review' => $this->getSchemaReviews()
];
}
public function getSchemaReviews() {
$reviewItems = [];
foreach ($this->Reviews()->sort('Created','DESC') as $review) {
$reviewItems[] = [
'@type' => 'Review',
'author' => [
'@type' => 'Person',
'name' => $review->Name
],
'reviewBody' => $review->Content,
'reviewRating' => [
'@type' => 'Rating',
'ratingValue' => $review->Rating,
'worstRating' => 1,
'bestRating' => 5
]
];
}
return $reviewItems;
}
Hopefully this is helpful to someone.