Created
October 26, 2022 07:11
-
-
Save GauravKhupse/f0cb3a0916af34760171ece6377d05c9 to your computer and use it in GitHub Desktop.
service_schmea_multiple_area_served_type_country
This file contains hidden or 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_service', '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-service']['subkeys']['area-served'] = array( | |
'label' => esc_html__( 'Areas Served', 'wp-schema-pro' ), | |
'type' => 'repeater', | |
'fields' => array( | |
'area-served' => array( | |
'label' => esc_html__( 'Area', 'wp-schema-pro' ), | |
'type' => 'text', | |
'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['area-served'] ) && ! empty( $data['area-served'] ) ) { | |
foreach ( $data['area-served'] as $key => $value ) { | |
if( isset( $value["area-served"] ) && '' != $value["area-served"] ) { | |
$schema['areaServed'][ $key ]['@type'] = 'Country'; | |
$schema['areaServed'][ $key ]['name'] = wp_strip_all_tags( $value['area-served'] ); | |
} | |
} | |
} | |
return $schema; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment