' . \"\\n\";\n}\nadd_action( 'wp_head', 'wp_local_business_schema' );","programmingLanguage":"PHP","codeRepository":"https://fysalyaqoob.com/snippets/local-business-schema-wordpress","url":"https://fysalyaqoob.com/snippets/local-business-schema-wordpress","datePublished":"2025-12-22","dateModified":"2025-12-22","keywords":"wordpress, local-business, schema, seo, structured-data, json-ld, google-maps, local-seo","about":{"@type":"Thing","name":"wordpress","description":"wordpress development"},"educationalLevel":"intermediate","isAccessibleForFree":true,"license":"https://opensource.org/licenses/MIT"}
PHPwordpressintermediate

Local Business Schema for WordPress

Add LocalBusiness JSON-LD structured data to WordPress for Google Maps and local search rich results

Faisal Yaqoob
#wordpress#local-business#schema#seo#structured-data#json-ld#google-maps#local-seo
Share this snippet:

Code

php
1/**
2 * Output LocalBusiness JSON-LD Schema
3 * Add to child theme functions.php
4 * Customize the values below for your business
5 */
6function wp_local_business_schema() {
7 // Only output on homepage or contact page
8 if ( ! is_front_page() && ! is_page( 'contact' ) ) {
9 return;
10 }
11
12 $schema = [
13 '@context' => 'https://schema.org',
14 '@type' => 'LocalBusiness',
15 // Change @type to specific subtypes for better matching:
16 // Restaurant, Dentist, LegalService, RealEstateAgent,
17 // AutomotiveBusiness, BeautySalon, FinancialService, etc.
18 'name' => get_bloginfo( 'name' ),
19 'description' => get_bloginfo( 'description' ),
20 'url' => home_url( '/' ),
21 'telephone' => '+1-555-123-4567',
22 'email' => 'info@yourbusiness.com',
23 'image' => get_site_icon_url( 512 ),
24 'logo' => get_site_icon_url( 512 ),
25 'priceRange' => '$$',
26 'address' => [
27 '@type' => 'PostalAddress',
28 'streetAddress' => '123 Main Street',
29 'addressLocality' => 'New York',
30 'addressRegion' => 'NY',
31 'postalCode' => '10001',
32 'addressCountry' => 'US',
33 ],
34 'geo' => [
35 '@type' => 'GeoCoordinates',
36 'latitude' => '40.7128',
37 'longitude' => '-74.0060',
38 ],
39 'openingHoursSpecification' => [
40 [
41 '@type' => 'OpeningHoursSpecification',
42 'dayOfWeek' => [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday' ],
43 'opens' => '09:00',
44 'closes' => '18:00',
45 ],
46 [
47 '@type' => 'OpeningHoursSpecification',
48 'dayOfWeek' => 'Saturday',
49 'opens' => '10:00',
50 'closes' => '14:00',
51 ],
52 ],
53 'sameAs' => [
54 'https://www.facebook.com/yourbusiness',
55 'https://www.instagram.com/yourbusiness',
56 'https://www.linkedin.com/company/yourbusiness',
57 'https://maps.google.com/?cid=YOUR_GOOGLE_CID',
58 ],
59 ];
60
61 echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) . '</script>' . "\n";
62}
63add_action( 'wp_head', 'wp_local_business_schema' );

Local Business Schema for WordPress

Add comprehensive LocalBusiness structured data to your WordPress site to appear in Google's local pack, Maps, and Knowledge Panel. This is essential for any business with a physical location or service area.

LocalBusiness Schema with Opening Hours

/**
 * Output LocalBusiness JSON-LD Schema
 * Add to child theme functions.php
 * Customize the values below for your business
 */
function wp_local_business_schema() {
    // Only output on homepage or contact page
    if ( ! is_front_page() && ! is_page( 'contact' ) ) {
        return;
    }

    $schema = [
        '@context'    => 'https://schema.org',
        '@type'       => 'LocalBusiness',
        // Change @type to specific subtypes for better matching:
        // Restaurant, Dentist, LegalService, RealEstateAgent,
        // AutomotiveBusiness, BeautySalon, FinancialService, etc.
        'name'        => get_bloginfo( 'name' ),
        'description' => get_bloginfo( 'description' ),
        'url'         => home_url( '/' ),
        'telephone'   => '+1-555-123-4567',
        'email'       => 'info@yourbusiness.com',
        'image'       => get_site_icon_url( 512 ),
        'logo'        => get_site_icon_url( 512 ),
        'priceRange'  => '$$',
        'address'     => [
            '@type'           => 'PostalAddress',
            'streetAddress'   => '123 Main Street',
            'addressLocality' => 'New York',
            'addressRegion'   => 'NY',
            'postalCode'      => '10001',
            'addressCountry'  => 'US',
        ],
        'geo'         => [
            '@type'     => 'GeoCoordinates',
            'latitude'  => '40.7128',
            'longitude' => '-74.0060',
        ],
        'openingHoursSpecification' => [
            [
                '@type'     => 'OpeningHoursSpecification',
                'dayOfWeek' => [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday' ],
                'opens'     => '09:00',
                'closes'    => '18:00',
            ],
            [
                '@type'     => 'OpeningHoursSpecification',
                'dayOfWeek' => 'Saturday',
                'opens'     => '10:00',
                'closes'    => '14:00',
            ],
        ],
        'sameAs'      => [
            'https://www.facebook.com/yourbusiness',
            'https://www.instagram.com/yourbusiness',
            'https://www.linkedin.com/company/yourbusiness',
            'https://maps.google.com/?cid=YOUR_GOOGLE_CID',
        ],
    ];

    echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) . '</script>' . "\n";
}
add_action( 'wp_head', 'wp_local_business_schema' );

Dynamic LocalBusiness from Theme Customizer

/**
 * Register Customizer settings for business info
 */
function business_schema_customizer( $wp_customize ) {
    $wp_customize->add_section( 'business_schema', [
        'title'    => 'Business Schema',
        'priority' => 200,
    ] );

    $fields = [
        'business_phone'     => 'Phone Number',
        'business_email'     => 'Email Address',
        'business_street'    => 'Street Address',
        'business_city'      => 'City',
        'business_state'     => 'State/Region',
        'business_zip'       => 'Postal Code',
        'business_country'   => 'Country Code (e.g. US)',
        'business_latitude'  => 'Latitude',
        'business_longitude' => 'Longitude',
        'business_price'     => 'Price Range (e.g. $$)',
    ];

    foreach ( $fields as $id => $label ) {
        $wp_customize->add_setting( $id, [ 'default' => '' ] );
        $wp_customize->add_control( $id, [
            'label'   => $label,
            'section' => 'business_schema',
            'type'    => 'text',
        ] );
    }
}
add_action( 'customize_register', 'business_schema_customizer' );

/**
 * Output dynamic LocalBusiness schema from Customizer values
 */
function wp_dynamic_local_business_schema() {
    if ( ! is_front_page() && ! is_page( 'contact' ) ) {
        return;
    }

    $phone = get_theme_mod( 'business_phone', '' );
    if ( empty( $phone ) ) {
        return; // Skip if not configured
    }

    $schema = [
        '@context'    => 'https://schema.org',
        '@type'       => 'LocalBusiness',
        'name'        => get_bloginfo( 'name' ),
        'description' => get_bloginfo( 'description' ),
        'url'         => home_url( '/' ),
        'telephone'   => $phone,
        'email'       => get_theme_mod( 'business_email', '' ),
        'priceRange'  => get_theme_mod( 'business_price', '$$' ),
        'address'     => [
            '@type'           => 'PostalAddress',
            'streetAddress'   => get_theme_mod( 'business_street', '' ),
            'addressLocality' => get_theme_mod( 'business_city', '' ),
            'addressRegion'   => get_theme_mod( 'business_state', '' ),
            'postalCode'      => get_theme_mod( 'business_zip', '' ),
            'addressCountry'  => get_theme_mod( 'business_country', 'US' ),
        ],
    ];

    $lat = get_theme_mod( 'business_latitude', '' );
    $lng = get_theme_mod( 'business_longitude', '' );
    if ( $lat && $lng ) {
        $schema['geo'] = [
            '@type'     => 'GeoCoordinates',
            'latitude'  => $lat,
            'longitude' => $lng,
        ];
    }

    echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES ) . '</script>' . "\n";
}
add_action( 'wp_head', 'wp_dynamic_local_business_schema' );

Multi-Location Support

/**
 * Schema for businesses with multiple locations
 * Uses a custom post type 'location'
 */
function wp_multi_location_schema() {
    if ( ! is_singular( 'location' ) ) {
        return;
    }

    global $post;

    $schema = [
        '@context'    => 'https://schema.org',
        '@type'       => 'LocalBusiness',
        'name'        => get_the_title(),
        'description' => get_the_excerpt(),
        'url'         => get_permalink(),
        'telephone'   => get_post_meta( $post->ID, 'location_phone', true ),
        'address'     => [
            '@type'           => 'PostalAddress',
            'streetAddress'   => get_post_meta( $post->ID, 'location_street', true ),
            'addressLocality' => get_post_meta( $post->ID, 'location_city', true ),
            'addressRegion'   => get_post_meta( $post->ID, 'location_state', true ),
            'postalCode'      => get_post_meta( $post->ID, 'location_zip', true ),
            'addressCountry'  => get_post_meta( $post->ID, 'location_country', true ),
        ],
        'geo'         => [
            '@type'     => 'GeoCoordinates',
            'latitude'  => get_post_meta( $post->ID, 'location_lat', true ),
            'longitude' => get_post_meta( $post->ID, 'location_lng', true ),
        ],
        'parentOrganization' => [
            '@type' => 'Organization',
            'name'  => get_bloginfo( 'name' ),
            'url'   => home_url( '/' ),
        ],
    ];

    echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES ) . '</script>' . "\n";
}
add_action( 'wp_head', 'wp_multi_location_schema' );

Business Type Reference

// Common LocalBusiness subtypes for @type:
// Use the most specific type that matches your business

// Food & Drink
// 'Restaurant', 'CafeOrCoffeeShop', 'BarOrPub', 'Bakery', 'FastFoodRestaurant'

// Health & Medical
// 'Dentist', 'Physician', 'Optician', 'Pharmacy', 'VeterinaryCare'

// Professional Services
// 'LegalService', 'AccountingService', 'FinancialService', 'InsuranceAgency'

// Home Services
// 'Plumber', 'Electrician', 'HVACBusiness', 'LocksmithService', 'RoofingContractor'

// Beauty & Wellness
// 'BeautySalon', 'HairSalon', 'DaySpa', 'NailSalon', 'TattooParlor'

// Automotive
// 'AutoRepair', 'AutoDealer', 'GasStation', 'AutoBodyShop'

// Retail
// 'Store', 'ClothingStore', 'ElectronicsStore', 'HardwareStore', 'ShoeStore'

// Fitness & Recreation
// 'HealthClub', 'GolfCourse', 'SportsActivityLocation', 'BowlingAlley'

Best Practices

  • Use the most specific @typeRestaurant ranks better than generic LocalBusiness
  • Include geo coordinates — essential for Google Maps integration
  • Add openingHoursSpecification — Google displays hours in Knowledge Panel
  • Keep NAP consistent — Name, Address, Phone must match Google Business Profile
  • Include sameAs with your Google Maps CID and social profiles
  • Add aggregateRating if you have legitimate reviews on your site

Features

  • Google Local Pack: Appear in "near me" searches
  • Knowledge Panel: Populate Google Knowledge Panel with business details
  • Maps Integration: Automatic Google Maps linking via geo coordinates
  • Opening Hours: Display business hours in search results
  • Multi-Location: Support for businesses with multiple branches
  • Customizer Integration: Non-developers can update via WordPress admin

Related Snippets