Add an Extended Store Schema Type to ‘Business Profile’ WordPress Plugin

Business Profile WordPress plugin feeds some rich Google microdata schema to search, you can extend what is available in the plugin to other known schema for a business.

This example uses a Florist as an example, Florist is a valid schema under Store but does not appear in the plugin dropdown options. For other valid schemas, search at schema.org

<?php
/**
* Plugin Name: Business Profile Business Exttnder
* Plugin URI: http://wpbeaches.com
* Description: Modifies the Business Profile plugin to include extra info for business.
* Version: 0.0.1
* Author: Neil Gowran
* Author URI: http://wpbeaches.com
* License: GNU General Public License v2.0 or later
* Reference - https://gist.github.com/NateWr/b28bb63ba8a73bb14eac
*/
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* Add Schema options for a local business store which is a florist store
*
* This preserves the existing options and just adds the one for
* Florist which is a sublevel of Store. But if your working in an environment where
* these are the only options you'll need, you can replace the options
* array instead of adding to it.
*/
add_filter( 'bpfwp_settings_page', 'prefix_extend_schema', 100 );
// This example is using the themes prefix of prefix to extend the plugin which uses bpfwp
function prefix_extend_schema( $sap ) {
// Loop over the schema options. When we hit the
// Store option which already exists, add in our florist business schema.
$new_schema_options = array();
foreach ( $sap->pages['bpfwp-settings']->sections['bpfwp-seo']->settings['schema_type']->options as $schema => $label ) {
$new_schema_options[$schema] = $label;
if ( $schema == 'Store' ) {
$new_schema_options['Florist'] = '-- Florist';// Adding in new schema
}
}
// Replace the existing schema options with the new ones
$sap->pages['bpfwp-settings']->sections['bpfwp-seo']->settings['schema_type']->options = $new_schema_options;
return $sap;
}

The plugin filters in with bpfwp_settings_page , when the array of the original values hits our parent element which in this case is ‘Store’ we add in the new schema child which is ‘Florist’ and add the sub-level ‘__Florist’

Now you can add this via the plugin.

The new schema is output in the markup.

schema-output

Leave all Comment