|
| 1 | +## Schema Usage |
| 2 | + |
| 3 | +Based on Justin Tadlock's `hybrid_attr()` functions from older versions of [Hybrid Core](https://github.com/justintadlock/hybrid-core). Justin has since removed the schema.org attributes from the functions and they are resurected here. |
| 4 | + |
| 5 | +This provider is still a work in progress. It is functional, but has quirks. For instance, I am having problems using the `@schema()` directive using `@include` in an already included partial for some reason. |
| 6 | + |
| 7 | +Another quirk is the original `hybrid_attr()` function allowed for a third `$args` parameter array. You are able to pass stuff like `['class'=>'col-med-4 col-sm-12']` and have that rolled into the attributes. Doing something like this using a single Blade string called `$expression` is tough. At any rate, the same thing can be handled via filters. |
| 8 | + |
| 9 | +### Attributes |
| 10 | +For the most part, adding schema.org attributes is pretty straight forward. You just add `@schema('slug')` to your Blade files. The slug names can be found in the filters section below. |
| 11 | + |
| 12 | +Some slugs need a little more explanation. |
| 13 | + |
| 14 | +`@schema('body')` for the `<body>` tag automatically joins the `get_body_class()` into the list of classes. It also detects what type of page/post is being displayed and will act accordingly and set `itemtype` to WebPage, Blog, or SearchResultsPage. |
| 15 | + |
| 16 | +Three of the schemas require a second parameter: |
| 17 | +- `@schema('sidebar,context')` Where context is the Id of the sidebar |
| 18 | +- `@schema('menu,context')` Where context is the Id of the menu |
| 19 | +- `@schema('entry-terms,context')` Where context is optional. It can either be `category` or `post_tag` and will add an `itemprop` of 'articleSection' or 'keywords' respectively. If omitted, no itemprop will be defined. |
| 20 | + |
| 21 | +Three of the schemas reveal the fact that the blog is WordPress. If you have any plugins or custom code to hide this fact, you may wish to avoid using them. They are `@schema('header')`, `@schema('footer')`, and `@schema('sidebar')` which adds an `itemstype` of WPHeader, WPFooter, and WPSidebar respectively. Of course, you can add your own filters to change `itemtype` attributes. |
| 22 | + |
| 23 | +### Filters |
| 24 | +All filters have a priority of 5 and one argument, except for `sage_schema_sidebar`, `sage_schema_menu`, and `sage_schema_entry-terms`. Those exceptions require a second `$context` argument. For instance `@schema('sidebar, primary')`. |
| 25 | + |
| 26 | +Each filter follows a pattern `sage_schema_{$slug}`. Slugs are hyphenated. |
| 27 | + |
| 28 | +Additionally, there is a second set of matching filters for customizing `class` attributes. They follow a similar pattern `sage_schema_{$slug}_class` |
| 29 | + |
| 30 | +**Schema for major structural elements.** |
| 31 | +- `sage_schema_body` |
| 32 | +- `sage_schema_header` |
| 33 | +- `sage_schema_footer` |
| 34 | +- `sage_schema_content` |
| 35 | +- `sage_schema_sidebar` (2) |
| 36 | +- `sage_schema_menu` (2) |
| 37 | + |
| 38 | +**Header schema.** |
| 39 | +- `sage_schema_head` |
| 40 | +- `sage_schema_branding` |
| 41 | +- `sage_schema_site-title` |
| 42 | +- `sage_schema_site-description` |
| 43 | + |
| 44 | +**Archive page header schema.** |
| 45 | +- `sage_schema_archive-header` |
| 46 | +- `sage_schema_archive-title` |
| 47 | +- `sage_schema_archive-description` |
| 48 | + |
| 49 | +**Post-specific schema.** |
| 50 | +- `sage_schema_post` |
| 51 | +- `sage_schema_entry` (Alias for "post") |
| 52 | +- `sage_schema_entry-title` |
| 53 | +- `sage_schema_entry-author` |
| 54 | +- `sage_schema_entry-published` |
| 55 | +- `sage_schema_entry-content` |
| 56 | +- `sage_schema_entry-summary` |
| 57 | +- `sage_schema_entry-terms` (2) |
| 58 | + |
| 59 | +**Comment specific schema.** |
| 60 | +- `sage_schema_comment` |
| 61 | +- `sage_schema_comment-author` |
| 62 | +- `sage_schema_comment-published` |
| 63 | +- `sage_schema_comment-permalink` |
| 64 | +- `sage_schema_comment-content` |
0 commit comments