An all-in-one SEO module for SilverStripe.
Note: For original module please see quinninteractive/silverstripe-seo
.
- SEO Health Analysis in the Page Editor ![SEO Health Analysis]
- Automatic Facebook OpenGraph meta-tag generation (can override) ![Facebook SEO Control]
- Automatic Twitter meta-tag generation (can override) ![Twitter SEO Control]
- Also adds a
TwitterAccountName
field toSilverStripe\Security\Member
which is used for the creator tag. The creator is recorded when a new page is created and their Twitter account name will be used for the meta tag
- Also adds a
<link rel="canonical" href="http://sample.com/"/>
<meta property="og:title" content="Home"/>
<meta property="og:description" content="Sample Website creates boring old samples."/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://sample.com/"/>
<meta property="og:locale" content="en_GB" />
<meta property="og:site_name" content="Sample Website" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Home"/>
<meta name="twitter:description" content="Sample Website creates boring old samples."/>
<meta name="twitter:creator" content="@sample"/>
<meta name="twitter:site" content="@sample" />
<meta property="article:published_time" content="2020-04-08T00:22:10+10:00" />
<meta property="article:modified_time" content="2020-04-16T21:52:52+10:00" />
See composer.json for details.
composer require jellygnite/silverstripe-seo
The necessary extensions are automatically applied after installation of this module, and a dev/build.
Health analyses have been abstracted to give developers the ability to create their own analysis checks.
To do this, you simply need to create a new class that extends Jellygnite\Seo\Analysis\Analysis
.
As an example, let's create a new analysis that checks to see if Hello World!
is the title of the current page.
First create the following file:
mysite\code\Analysis\HelloWorldTitleAnalysis.php
<?php
namespace Vendor\Project\Analysis;
use Jellygnite\Seo\Analysis\Analysis;
class HelloWorldTitleAnalysis extends Analysis
{
const FAILED = 0;
const SUCCESS = 1;
public function run()
{
if (!strstr($this->getPage()->Title, 'Hello World!')) {
return static::FAILED;
}
return static::SUCCESS;
}
public function responses()
{
return [
static::FAILED => ['The string "Hello World!" does not appear in the page title', 'danger'],
static::SUCCESS => ['Hoorah!!! "Hello World!" appears in the page title', 'success'],
];
}
}
Then dev/build. You will immediately see this new analysis running in the CMS under the "SEO Health Analysis" accordion when editing any page, then change the title to include "Hello World" and you will notice the indicator will display success.
One thing to keep in mind is that the analysis always has access to the \Page
object that it is running against via $this->getPage()
, so your responses can also be dynamic.
If you have created an analysis and think it would be beneficial as an addition to this module then we urge you to submit a Pull Request and you will receive full credit for your work. See CONTRIBUTING.md.
You must override this method as this is where you will perform all your checks, and then return with an integer respective of the keys you define in responses()
. It's a good idea to use constants that represent those integers for readability
All analyses must override the responses()
method to provide response messages and the response level (which is used for the indicator).
run()
should return an integer that matches a key in the array that responses()
returns, for example if run()
were to return 1
, then using the above example the message displayed would be Hoorah!!! "Hello World!" appears in the page title
with an indicator level of success
The available indicator levels are: default
, danger
, warning
, success
which are grey, red, orange and green respectively.
You can optionally prevent certain levels from displaying in the content analysis tab. The following added to the above example would cause it to only display an entry if the indicator level is not of value success
:
private static $hidden_levels = [
'success'
];
By default, this module adds an extension to \SilverStripe\Security\Member
that adds a single field named TwitterAccountName
, if this is set
and when this particular user creates a page, the twitter:creator
meta tag will automatically generate with the Members account name
You can disable this via YML:
Jellygnite\Seo\Extensions\PageSeoExtension:
enable_creator_tag: false
This module assumes that you make use of the default Content
field provided by \Page
. If a specific page does not then you can specify one or multiple fields that contain your content.
They should be ordered in the correct order that they appear for the end user
In your \Page
subclass you would have:
public function seoContentFields()
{
return [
'Content',
'MyBlock.Title',
'MyBlock.Content',
'BottomTitle',
'BottomContent',
];
}