Created
February 4, 2022 09:39
-
-
Save GauravKhupse/1e22e095b61fbd5e98b65ed94e466892 to your computer and use it in GitHub Desktop.
Place field in the Article schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_article', '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-article']['subkeys']['contentLocation'] = array( // `bsf-aiosrs-book` used for Book, `bsf-aiosrs-event` will for Event like that. | |
'label' => esc_html__( 'Place', 'aiosrs-pro' ), // Label to display in Mapping fields | |
'type' => 'text', // text/date/image | |
'default' => 'none', | |
'required' => true, // true/false. | |
); | |
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 ) { | |
$schema['contentLocation']['@type'] = 'Place'; | |
if ( isset( $data['contentLocation'] ) && ! empty( $data['contentLocation'] ) ) { | |
$schema['contentLocation']['name'] = esc_html( $data['contentLocation'] ); | |
} | |
return $schema; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment