sitecrafting / conifer

:evergreen_tree: A powerful WordPress library plugin for OO development
https://www.coniferplug.in
MIT License
18 stars 2 forks source link

Feature: JSON+LD schema markup #127

Open acobster opened 4 years ago

acobster commented 4 years ago

As a Conifer dev user, I want to be able to output schema markup for posts as JSON-LD data. Something like:

<article>
  <h2>{{ post.title }}</h2>
  <script type="application/ld+json">{{ post.json_ld() }}</script>
</article>

Acceptance Criteria

Possible usage:

namespace Project\Post;

use Conifer\Post\Post;
use Conifer\Schema\HasStructureDataMarkup;

class Event extends Post {
  use HasStructuredDataMarkup;

  const POST_TYPE = 'event';

  protected function schema_markup() : array {
    return [
      '@type'    => 'Event',
      'headline' => $this->title(),
      // ...
    ];
  }
}

In the future, we may look at enhancing the trait with other microformats, although there probably isn't a big advantage there.