Add a LocalBusiness to the Yoast Schema Graph
Adds a LocalBusiness node with address, phone and opening hours to the Yoast SEO graph on the homepage and links it to Yoast's Organization.
Opens WPIDE on
Code
// Your business details.
$wpide_local = array(
'type' => 'LocalBusiness',
'name' => get_bloginfo( 'name' ),
'phone' => '+1-555-010-0199',
'street' => '123 Main Street',
'city' => 'Springfield',
'region' => 'IL',
'zip' => '62701',
'country' => 'US',
'hours' => array( 'Mo-Fr 09:00-17:00', 'Sa 10:00-14:00' ),
'price' => '$$',
);
add_filter( 'wpseo_schema_graph', function ( $graph ) use ( $wpide_local ) {
if ( ! is_array( $graph ) || ! is_front_page() ) {
return $graph;
}
$graph[] = array(
'@type' => $wpide_local['type'],
'@id' => home_url( '/#localbusiness' ),
'name' => $wpide_local['name'],
'url' => home_url( '/' ),
'telephone' => $wpide_local['phone'],
'priceRange' => $wpide_local['price'],
'openingHours' => $wpide_local['hours'],
'parentOrganization' => array( '@id' => home_url( '/#organization' ) ),
'address' => array(
'@type' => 'PostalAddress',
'streetAddress' => $wpide_local['street'],
'addressLocality' => $wpide_local['city'],
'addressRegion' => $wpide_local['region'],
'postalCode' => $wpide_local['zip'],
'addressCountry' => $wpide_local['country'],
),
);
return $graph;
} );
Notes
Use a more specific type such as Restaurant or Dentist. Yoast Local SEO users already have this.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.