Schema

Schema is the best way to describes structured data for search engines. Based on the data provided, search engines can show the content in the search results page in a more appealing way.

In version 2.0, Slim SEO improves the way it outputs Schema data via JSON-LD. All the schema for entities are outputted in a single <script> tag in the footer. The plugin also provides connections between entities.

For example, if you’re on a single post, the plugin can tell search engines about the main entity of the page is an article, which belongs to a webpage. The webpage has a breadcrumb list, and belongs to a website, which has a search box.

Supported Schema Types

Slim SEO adds various schemas for different entities depending on the context of the current page. The sections below describes the schemas, omitting the @type and @id properties since they’re just technical terms.

Global schemas

These are global schemas that are outputted for every page:

  • Website
  • Webpage
    • Name
    • Description
    • Language
    • URL
    • Date published (for singular pages)
    • Date modified (for singular pages)
    • Primary image of page (for singular pages)
    • Image (for singular pages)
  • Breadcrumbs

Specification per page type

Single posts

For single posts, the plugin adds the following schema:

  • Article
    • Headline
    • URL
    • Date published
    • Date modified
    • Comment count
    • Word count
    • Keywords: list of post tags
    • Sections: list of categories
  • Author
    • Name
    • Given name (first name)
    • Family name (last name)
    • Description
    • Image: reference to user gravatar

Archive pages

For archive pages: category page, tag page, post type archive page, date archive page, the @type of Webpage becomes CollectionPage.

Search result pages

For search result pages, the @type of Webpage becomes SearchResultsPage.

Author pages

For search result pages, the @type of Webpage becomes ProfilePage. And there is a new schema Person with the following data:

  • Name
  • Given name (first name)
  • Family name (last name)
  • Description
  • Image: reference to user gravatar

How to disable schema output?

To disable the schema feature, please use the following code:

add_filter( 'slim_seo_schema_enable', '__return_false' );

How to disable a specific schema?

Each schema can be disabled with a filter. For example, to disable schema for breadcrumbs, use the following code:

add_filter( 'slim_seo_schema_breadcrumbs_enable', '__return_false' );

In general, to disable a specific schema, use the following code:

add_filter( "slim_seo_schema_{$context}_enable", '__return_false' );

Where $context is the schema context, which can be referred below:

SchemaContext
Websitewebsite
Search actionsearchaction
Webpagewebpage
Breadcrumbsbreadcrumbs
Articlearticle
Authorauthor

How to modify the schema output of a specific type?

To modify the output of a specific schema type, please use the following code:

add_filter( "slim_seo_schema_{$context}", function ( $schema ) {
// Add or modify a property.
$schema['some_property'] = 'Some value';

// Or remove a property.
unset( $schema['another_property'];

return $schema;
} );

The $context is the same as the previous section.

How to add more schemas?

Sometimes, you want to add more schemas to provide more information about the page, such as a product page or about page. To do that, use the following code:

add_filter( 'slim_seo_schema_entities', function( $entities ) {
$entity = new YourEntityClass(); // Will be defined below.
$entities[] = $entity;

// You can connect this entity to another existing entities like this.
$entity->add_reference( 'author', $entities['author'] );
$entity->add_reference( 'isPartOf', $entities['webpage'] );

return $entities;
} );

You need to create a schema entity class (YourEntityClass) which inherits the SlimSEO\Schema\Types\Base class. And it has to provide a generate methods to return an array of properties:

class YourEntityClass extends SlimSEO\Schema\Types\Base {
protected function generate() {
$schema = [
'property_1' => 'Value 1',
'property_2' => 'Value 2',
];

return $schema;
}
}

You can take a look at the code of Webpage schema for an example.