To help users further customize their schema markup generated by our Wordpress plugins, we provide two filters. Wordpress Filters allow users to check or replace content such as Schema markup within plugins or themes. For our Base Plugin, we have created the following filters

  • hunch_schema_markup 
  • hunch_schema_markup_breadcrumb 

Both filters provide an argument $PostType, so as to further allow plugins to filter output based on Post Types. 


This is an example for modifying WP Product schema markup: 

function addSuccessorOfSchema ( $schema_markup, $schema_markup_type, $post, $post_type ) {
  
  if ( is_product() && ! empty( $schema_markup ) ) {
    $product = wc_get_product( get_the_ID() );

    if ( $product->get_attribute( 'successorOf' ) ) {
      $schema_markup = json_decode( $schema_markup );
      $schema_markup->successorOf = $product->get_attribute( 'successorOf' ); 
      $schema_markup = json_encode( $schema_markup );
    }
  }
 
  return $schema_markup;
}
add_filter( 'hunch_schema_markup', 'addSuccessorOfSchema', 10, 4 );


For custom BlogPosting Author:

function schema_markup_custom_author ( $schema_markup, $schema_markup_type, $post, $post_type ) {
  
  if ( ! empty( $schema_markup ) ) {
    $schema_markup = json_decode( $schema_markup );
    
    if ( $schema_markup->{'@type'} == 'BlogPosting' ) {
      $schema_markup->author = array(
        '@type' => 'Person',
        '@id' => 'http://example.com/author/jone-doe/#Person',
        'name' => 'Jone Doe',
        'url' => 'http://example.com/author/jone-doe/',
      );
      $schema_markup = json_encode( $schema_markup );
    }
  } 

  return $schema_markup;
}
add_filter( 'hunch_schema_markup', 'schema_markup_custom_author', 10, 4 );