No results found. Try again with different words?

Search must be at least 3 characters.

    How to Add an Extra Field for a Particular Schema Type in Schema Pro?

    Docs » General » How to Add an Extra Field for a Particular Schema Type in Schema Pro?

    Schema Pro allows you to add an extra field for a particular schema type.

    You will need to use 2 filters to be able to add an extra field.

    1. wp_schema_pro_schema_meta_fields: This filter is used to add your extra field for mapping.
    2. wp_schema_pro_schema_{$schema_type}: This filter is used to map the extra field with schema field. Here $schema_type should be replaced with your schema type for which you wish to add an extra field. You can use the following schema types.   articlebookcourseeventjob_postinglocal_businessreviewpersonproduct,
      recipeservicesoftware_applicationvideo_object

    Here is an example you can refer to:

    Example: Add a field workExample in local_business Schema type. Add following code in your functions.php file. Here work-example is used as a key for the workExample field.

    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']['work-example'] = array( // `bsf-aiosrs-book` used for Book, `bsf-aiosrs-event` will for Event like that.
    		'label'    => esc_html__( 'workExample', 'wp-schema-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 ) {
    
    	if ( isset( $data['work-example'] ) && ! empty( $data['work-example'] ) ) {
    		// For date/text type field
    		$schema['workExample'] = esc_html( $data['work-example'] );
    
    		// For image type field
    		// $schema['workExample'] = BSF_AIOSRS_Pro_Schema_Template::get_image_schema( $data['work-example'] );
    	}
    	return $schema;
    }

    Was this article helpful?

    Did not find a solution? We are here to help you succeed.

    Related Docs

    Scroll to Top