PMC Structured Data
Overview
This plugin aims to simplify our structured data used for search engines mainly google. It provides an easy to use filterable json object which our sites can utilize to output the necessary json markup in the header of applicable pages. This allows us the opportunity to remove and decouple our item schema from our html code and into one consolidated object which reduces the chance of conflicting data.
How to install the plugin
load_pmc_plugins to load pmc-structured-data.
Removing items from markup
It is also necessary to remove any references to itemscope, itemtype, itemprop, and any other type reference which defines the pages structure from the theme.
Resources
Google's Structured Data Intro: https://developers.google.com/search/docs/guides/intro-structured-data (opens in a new tab)
JSON-LD format: https://json-ld.org/ (opens in a new tab)
Structured data testing tool: https://search.google.com/structured-data/testing-tool (opens in a new tab)
JSON-LD vs Microdata: https://stackoverflow.com/questions/38091635/microdata-or-json-ld-im-confused (opens in a new tab) (note the comment about programmatic vs manual insertion, we're all programmatic)
Overriding the default settings
You can use the following filter to override the default json structure.
add_filter( PMC\Structured_Data\Article_Data::FILTER_DATA, function () {
return $data;
} );To activate plugin for all post types and/or change output location. Add these codes before init action fired
Article_Data::get_instance()
->render_on_action( 'wp_footer')
->activate_on_all_post_types( true );To identify free and/or paid content section with a css selector, multiple selectors are support for free + paid combo:
add_filter( Article_Data::FILTER_CONTENT_SELECTORS, function( $selectors ) {
$selectors[ '.section1' ] = 'free'; // free contents
$selectors[ '.section2' ] = 'paid'; // paid contents
// ....
return $selectors;
} );Site logo
It's important to note that on local/qa : production there is a difference in how the required publisher logo is fetched. On local/qa we are using get_site_icon_url which can usually be set in the 'Appearance -> customize' settings. Whereas on production ( VIP ) the site icon/logo is fetched via blavatar.