Skip to content

Instantly share code, notes, and snippets.

@schemapress
Last active September 28, 2017 19:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schemapress/abf19698e702da7f27787d9bcb033e53 to your computer and use it in GitHub Desktop.
Save schemapress/abf19698e702da7f27787d9bcb033e53 to your computer and use it in GitHub Desktop.
Extend / Override Schema.org JSON_LD Output https://schema.press/docs/extend-schema-output/
<?php //* do not include php tag
add_filter('schema_output', 'schema_wp_extend_output_987345256');
/**
* Extend / Override Schema Output
*
* @since 1.0
*/
function schema_wp_extend_output_987345256( $schema ) {
global $post;
if ( empty($schema) ) return;
// Debug
// echo '<pre>'; print_r($schema); echo '</pre>';
// Modify NewType to present the actual schema.org type
if ( $schema['@type'] != 'NewType' ) return $schema;
// Modify / Override values
$schema['title'] = 'New Title';
// Add new values
$schema['name'] = 'Event Name';
$schema['startDate'] = '2016-07-10T06:00';
// Unset extras
unset($schema['headline']);
unset($schema['author']);
unset($schema['publisher']);
unset($schema['ArticleSection']);
return $schema;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment