Local Business Structured Data
Adds LocalBusiness JSON-LD with your address, phone, opening hours and map location to the homepage, to support local search and map results.
Opens WPIDE on
Code
// Your business details.
$wpide_business = array(
'type' => 'LocalBusiness',
'name' => 'Acme Coffee Roasters',
'phone' => '+1-555-010-0199',
'street' => '123 Main Street',
'city' => 'Springfield',
'region' => 'IL',
'postcode' => '62701',
'country' => 'US',
'latitude' => '39.7817',
'longitude' => '-89.6501',
'price' => '$$',
// Opening hours: day codes Mo Tu We Th Fr Sa Su and 24h times.
'hours' => array( 'Mo-Fr 08:00-18:00', 'Sa 09:00-14:00' ),
);
add_action( 'wp_head', function () use ( $wpide_business ) {
if ( ! is_front_page() ) {
return;
}
$data = array(
'@context' => 'https://schema.org',
'@type' => $wpide_business['type'],
'name' => $wpide_business['name'],
'url' => home_url( '/' ),
'telephone' => $wpide_business['phone'],
'priceRange' => $wpide_business['price'],
'address' => array(
'@type' => 'PostalAddress',
'streetAddress' => $wpide_business['street'],
'addressLocality' => $wpide_business['city'],
'addressRegion' => $wpide_business['region'],
'postalCode' => $wpide_business['postcode'],
'addressCountry' => $wpide_business['country'],
),
'openingHours' => $wpide_business['hours'],
);
if ( $wpide_business['latitude'] && $wpide_business['longitude'] ) {
$data['geo'] = array(
'@type' => 'GeoCoordinates',
'latitude' => $wpide_business['latitude'],
'longitude' => $wpide_business['longitude'],
);
}
if ( has_custom_logo() ) {
$logo = wp_get_attachment_image_url( (int) get_theme_mod( 'custom_logo' ), 'full' );
if ( $logo ) {
$data['image'] = $logo;
}
}
echo '<script type="application/ld+json">' . wp_json_encode( array_filter( $data ), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG ) . "</script>\n";
} );
Notes
Fill in your details at the top. Use a more specific type such as Restaurant, Dentist or Store when one fits.
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.