Adding Customizable Business Info Schema in Theme

Whenever putting together a website for a business, you often have to type the businesses information out throughout the website. Whether its the phone number or company address, if something ever needs to change, it can be a nightmare to try and replace all the instances that you (or they within posts) used the info. To get around this potential issue I like to define the generic company information on the back-end, and output it via shortcodes. To make it even better, we can utilize HTML5 schema microdata to define to “bots” what this information represents.

This is only for Genesis child themes ONLY. If you are not using Genesis, then this won’t work.

Our custom Genesis admin page
This is the page that is created on the back-end for you to enter your company details. Our short-codes will pull its information from these fields, and wrap the necessary schema around it when necessary.

 

Step 1: Create The Custom Admin Menu Item & Page

First, you need to add a page to the admin area where you can change and save your information. I like to keep this big chunk of code in its own file instead of just pasting it in my main functions. It just keeps things neat and organized that way. Although it should still work out fine if you wanted to paste it in your functions file.

Below is the code that:

  • Adds our custom menu item under the Genesis admin menu
  • Creates the admin page with the fields

[php]
‘parent_slug’ => ‘genesis’,
‘page_title’ => ‘Organization Information’,
‘menu_title’ => ‘Other Settings’,
‘capability’ => ‘manage_options’,
)
);

$page_ops = array(
‘screen_icon’ => ‘users’,
);

$settings_field = CHILD_SETTINGS_FIELD;

// Default values
$default_settings = array(
‘bpmtheme_office_phone’ => ”,
‘bpmtheme_company’ => ”,
‘bpmtheme_email’ => ”,
‘bpmtheme_fax’ => ”,
‘bpmtheme_street_address’ => ”,
‘bpmtheme_city’ => ”,
‘bpmtheme_state’ => ”,
‘bpmtheme_zip’ => ”,
‘bpmtheme_description’ => ”,

);

// Create
$this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings );

// Init sanitization
add_action( ‘genesis_settings_sanitizer_init’, array( $this, ‘sanitization_filters’ ) );

} // End contruct

// Set up Sanitization Filters
function sanitization_filters() {

genesis_add_option_filter( ‘no_html’, $this->settings_field,
array(
‘bpmtheme_office_phone’,
‘bpmtheme_email’,
‘bpmtheme_company’,
‘bpmtheme_fax’,
‘bpmtheme_street_address’,
‘bpmtheme_city’,
‘bpmtheme_state’,
‘bpmtheme_zip’,
‘bpmtheme_description’,
) );
}

function metaboxes() {
add_meta_box(‘contact-information’, ‘Contact Info’, array( $this, ‘bpmtheme_contact_information’ ), $this->pagehook, ‘main’, ‘high’);
}

function bpmtheme_contact_information() {

echo ‘

Enter your personal information here. This will be used site-wide and create shortcodes for

‘;

echo ‘

Company Name:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

Office Phone:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

Email:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

Fax:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

Street Address:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

City:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

State:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

Zip:
‘;
echo ‘‘;
echo ‘

‘;

echo ‘

Description
‘;
echo ‘

‘;
}
}

function bpmtheme_add_child_theme_settings() {
global $_child_theme_settings;
$_child_theme_settings = new Child_Theme_Settings;
}

add_action( ‘admin_menu’, ‘bpmtheme_add_child_theme_settings’, 5 );
[/php]

Output Your Company Information – Enhanced With Schema Microdata

Next, lets create the shortcodes that will output our information. This way, you can use them throughout your theme and within your content.

[php]
function addScInfo($type) {

$phone = genesis_get_option( ‘bpmtheme_office_phone’, CHILD_SETTINGS_FIELD );
$email = genesis_get_option( ‘bpmtheme_email’, CHILD_SETTINGS_FIELD );
$fax = genesis_get_option( ‘bpmtheme_fax’, CHILD_SETTINGS_FIELD );
$street = genesis_get_option( ‘bpmtheme_street_address’, CHILD_SETTINGS_FIELD );
$city = genesis_get_option( ‘bpmtheme_city’, CHILD_SETTINGS_FIELD );
$state = genesis_get_option( ‘bpmtheme_state’, CHILD_SETTINGS_FIELD );
$zip = genesis_get_option( ‘bpmtheme_zip’, CHILD_SETTINGS_FIELD );
$companydescription = genesis_get_option( ‘bpmtheme_description’, CHILD_SETTINGS_FIELD );
$company = genesis_get_option( ‘bpmtheme_company’, CHILD_SETTINGS_FIELD );

extract(shortcode_atts(array(
‘type’ => ‘type’
), $type));

// check what type user entered
switch ($type) {
case ‘phone’:
return $phone;
break;
case ’email’:
return $email;
break;
case ‘all’:
return ‘

‘.$company.’

‘.esc_html($companydescription).’

‘.esc_html($street).’,
‘.esc_html($city).’, ‘.$state.’, ‘.esc_html($zip).’, US


Phone: ‘.esc_html($phone).’
Fax: ‘.esc_html($fax).’

‘;
break;
}
}
add_shortcode(‘info’, ‘addScInfo’);
[/php]

Usage

Use shortcodes to output the data you need – instead of manually typing the info out every time. Now if something changes, it changes everywhere.

Example:

[info type=”phone”] will output the phone number
[info type=”email”] will output the email address
[info type=”all”] will output the full company information – wrapped up nicely in schema. Search engines will appreciate and hopefully reward you.

If you want to use shortcodes in widgets, mane sure you have this filter in your functions

[php]
add_filter(‘widget_text’, ‘do_shortcode’);
[/php]

If you want to use shortcodes within a template(via php)

[php]
echo do_shortcode(‘[info type=”all”]’);
[/php]

Below is the output on the front-end when you use our new shortcodes.

Now you can use shortcodes to output pieces of information about your company. And again, if you ever need to change your phone number or address, you can simply change it in one spot and have it change site-wide. And its wrapped in schema!

Suggestions? Let me know!