Skip to content

Instantly share code, notes, and snippets.

@GauravKhupse
Created December 30, 2021 12:32
Show Gist options
  • Save GauravKhupse/6b0bf87bd8d10bedfd1b82e6b8ea33b6 to your computer and use it in GitHub Desktop.
Save GauravKhupse/6b0bf87bd8d10bedfd1b82e6b8ea33b6 to your computer and use it in GitHub Desktop.
ServiceCusine field in Local business schema
add_action( 'after_setup_theme', 'add_my_custom_meta_field' );
function add_my_custom_meta_field() {
add_filter( 'wp_schema_pro_schema_meta_fields', 'my_extra_schema_field' );
add_filter( 'wp_schema_pro_schema_local_business', 'my_extra_schema_field_mapping', 10, 3 );
}
/**
* Add fields for mapping.
*
* @param array $fields Mapping fields array.
* @return array
*/
function my_extra_schema_field( $fields ) {
$fields['bsf-aiosrs-local-business']['subkeys']['servesCuisine'] = array( // `bsf-aiosrs-book` used for Book, `bsf-aiosrs-event` will for Event like that.
'label' => esc_html__( 'Serves Cuisine', 'wp-schema-pro' ), // Label to display in Mapping fields
'type' => 'text', // text/date/imaservesCuisinege
'default' => 'none',
);
return $fields;
}
/**
* Mapping extra field for schema markup.
*
* @param array $schema Schema array.
* @param array $data Mapping fields array.
* @return array
*/
function my_extra_schema_field_mapping( $schema, $data, $post ) {
if ( isset( $data['servesCuisine'] ) && ! empty( $data['servesCuisine'] ) ) {
$schema['servesCuisine'] = esc_html( $data['servesCuisine'] );
}
return $schema;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment