DEV Community

Cover image for How to Add LocalBusiness Schema to WordPress (Without a Plugin)
M.Saqib
M.Saqib

Posted on

How to Add LocalBusiness Schema to WordPress (Without a Plugin)

description: A copy-paste PHP snippet to add LocalBusiness JSON-LD to a WordPress site, including the setup for service-area businesses with a hidden address.

tags: wordpress, seo, php, webdev

When we rebuilt our agency's Google Business Profile, it went live but didn't show up when we searched our own name. One of the fixes was giving Google a clear, machine-readable description of the business on our website: LocalBusiness schema.

Schema won't magically rank you. What it does is tell Google, in structured data, that your website, your Business Profile and your social pages all belong to the same business. For a new or shared business name, that connection matters.

Here's how to add it to WordPress with a few lines of PHP, no extra plugin.

1. Pick the right type

LocalBusiness has more specific subtypes. Use the closest one:

Business Schema type
Agency, consultant, studio ProfessionalService
Cafe CafeOrCoffeeShop
Clinic MedicalClinic
Salon BeautySalon
Shop Store

2. The snippet

Add this to your child theme's functions.php, or as a PHP snippet in WPCode / Code Snippets. It outputs JSON-LD on the homepage only.

add_action( 'wp_head', function () {
    if ( ! is_front_page() ) {
        return;
    }

    $schema = [
        '@context'   => 'https://schema.org',
        '@type'      => 'ProfessionalService',
        '@id'        => home_url( '/#localbusiness' ),
        'name'       => 'Your Business Name',
        'url'        => home_url( '/' ),
        'logo'       => 'https://example.com/wp-content/uploads/logo.png',
        'image'      => 'https://example.com/wp-content/uploads/cover.jpg',
        'telephone'  => '+92-300-0000000',
        'email'      => 'info@example.com',
        'priceRange' => '$$',
        'address'    => [
            '@type'           => 'PostalAddress',
            'addressLocality' => 'Lahore',
            'addressRegion'   => 'Punjab',
            'addressCountry'  => 'PK',
        ],
        'areaServed' => [
            '@type' => 'City',
            'name'  => 'Lahore',
        ],
        'openingHoursSpecification' => [
            [
                '@type'     => 'OpeningHoursSpecification',
                'dayOfWeek' => [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ],
                'opens'     => '10:00',
                'closes'    => '19:00',
            ],
        ],
        'sameAs' => [
            'https://www.google.com/maps?cid=YOUR_CID',
            'https://www.facebook.com/yourpage',
            'https://www.instagram.com/yourhandle',
            'https://www.linkedin.com/company/yourcompany',
        ],
    ];

    echo '<script type="application/ld+json">'
        . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
        . '</script>' . "\n";
} );
Enter fullscreen mode Exit fullscreen mode

3. Service-area business? Leave the street out

If customers don't visit you and your Google Business Profile hides your address, don't put your street address in the schema either. Keep only the city, region and country (as above), and use areaServed for where you work. Your website and your profile should never disagree.

If customers do visit you, add streetAddress and postalCode, plus geo with your latitude and longitude.

4. Fill sameAs properly

sameAs is the part that ties everything together. List:

  • Your Google Maps URL (open your profile on Maps, use the link with cid=)
  • Facebook, Instagram, LinkedIn and any directory listings

Use the exact same business name and phone number everywhere.

5. Watch out for duplicates

SEO plugins like Yoast or Rank Math already output Organization schema. That's fine alongside LocalBusiness, but don't add a second LocalBusiness from a plugin and this snippet. View your page source, search for application/ld+json, and make sure there's only one.

6. Test it

  1. Run your homepage through the Schema Markup Validator.
  2. Run it through Google's Rich Results Test to check Google can read it.
  3. In Search Console, use URL Inspection and request indexing for the homepage.

Don't expect a visible "rich result" for LocalBusiness. The value is in Google understanding who you are, which helps your Business Profile and brand searches.

The bigger picture

Schema was one of five fixes that got our new profile showing for its own name. The others were a matching name and phone number in the site footer, consistent social profiles, genuine reviews, and weekly posts. We wrote up the whole process, including verification and the first 30 days, here:

👉 How to Set Up a Google Business Profile in Lahore (2027 Guide)

Written by Mursil Hamayoun, WordPress developer and founder of Pixelscape, a web development and digital marketing agency in Lahore.

Top comments (0)