🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Themes••By Komal Nakrani

LocalBusiness Schema in Astro: A Reusable JSON-LD Component

Add LocalBusiness schema to an Astro site with one typed JSON-LD component: address, hours, geo, service area, and the subtypes Google reads for local results.

#Astro#LocalBusiness Schema#JSON-LD#Structured Data#Local SEO

To add LocalBusiness schema in Astro, build one component that turns a typed business object into a <script type="application/ld+json"> tag with set:html={JSON.stringify(schema)}, then render it in the <head> of your home and contact pages. Use the most specific schema.org subtype you can (Dentist, Plumber, Restaurant), and make every value match what is visible on the page and in your Google Business Profile.

The rest of this guide gives you that component, a data file that keeps name, address and phone consistent across the site, and the checks to run before you ship.

Key Takeaways

  • LocalBusiness schema is JSON-LD in the page head. Astro renders it at build time, so crawlers see it without running JavaScript.
  • Keep business details in one TypeScript file and feed both the visible footer and the schema from it.
  • Pick the narrowest subtype: LegalService, Dentist, HomeAndConstructionBusiness, Restaurant.
  • Add openingHoursSpecification, geo, areaServed and sameAs only if the data is true and visible.
  • Validate with Google’s Rich Results Test and the Schema Markup Validator after every deploy.

What LocalBusiness schema does

LocalBusiness is a schema.org type for a business with a physical location or a defined service area. It tells search engines the facts they otherwise have to guess from your page: legal name, street address, phone, opening hours, coordinates, price range and the profiles that belong to the business.

It does not replace a Google Business Profile, and it is not a ranking switch. What it does is remove ambiguity. When your schema, your visible contact block and your Business Profile all say the same thing, search engines and AI answer engines have an easy, consistent source to quote. That consistency is most of what “local SEO” means for a small site.

Astro is a good fit because the output is plain HTML. There is no hydration step that could leave the JSON-LD missing for a crawler, and you can type the data so a missing postcode fails the build instead of silently shipping.

Keep business data in one place

The most common local SEO mistake is a phone number formatted three different ways across a site. Fix that before writing any schema by putting the business details in a single file.

// src/data/business.ts
export interface OpeningHours {
  days: ('Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday')[];
  opens: string;  // "09:00"
  closes: string; // "17:30"
}

export const business = {
  type: 'Dentist',
  name: 'Harbor Dental Studio',
  url: 'https://www.harbordental.example',
  telephone: '+1-555-010-2040',
  email: '[email protected]',
  priceRange: '$$',
  address: {
    streetAddress: '214 Water Street, Suite 3',
    addressLocality: 'Portland',
    addressRegion: 'ME',
    postalCode: '04101',
    addressCountry: 'US',
  },
  geo: { latitude: 43.6563, longitude: -70.2525 },
  hours: [
    { days: ['Monday', 'Tuesday', 'Wednesday', 'Thursday'], opens: '08:00', closes: '17:00' },
    { days: ['Friday'], opens: '08:00', closes: '13:00' },
  ] satisfies OpeningHours[],
  sameAs: [
    'https://www.facebook.com/harbordental.example',
    'https://www.linkedin.com/company/harbordental-example',
  ],
  logo: '/images/logo.png',
  image: '/images/clinic-front.jpg',
} as const;

Your footer, contact page and schema all import business. Change the phone once and every page agrees.

The LocalBusiness schema component

This component builds the object, resolves relative image paths against Astro.site, and prints it. Set site in astro.config.mjs first, otherwise Astro.site is undefined.

---
// src/components/LocalBusinessSchema.astro
import { business } from '../data/business';

const site = Astro.site ?? new URL(business.url);
const abs = (path: string) => new URL(path, site).href;

const schema = {
  '@context': 'https://schema.org',
  '@type': business.type,
  '@id': `${business.url}/#business`,
  name: business.name,
  url: business.url,
  telephone: business.telephone,
  email: business.email,
  priceRange: business.priceRange,
  logo: abs(business.logo),
  image: abs(business.image),
  address: {
    '@type': 'PostalAddress',
    ...business.address,
  },
  geo: {
    '@type': 'GeoCoordinates',
    latitude: business.geo.latitude,
    longitude: business.geo.longitude,
  },
  openingHoursSpecification: business.hours.map((h) => ({
    '@type': 'OpeningHoursSpecification',
    dayOfWeek: h.days,
    opens: h.opens,
    closes: h.closes,
  })),
  sameAs: business.sameAs,
};
---
<script type="application/ld+json" set:html={JSON.stringify(schema)} />

Then drop it into your layout’s head, or only on the pages that are about the business itself:

---
// src/pages/index.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import LocalBusinessSchema from '../components/LocalBusinessSchema.astro';
---
<BaseLayout title="Harbor Dental Studio | Dentist in Portland, ME">
  <LocalBusinessSchema slot="head" />
  <h1>Family dentistry on the Portland waterfront</h1>
</BaseLayout>

The slot="head" line assumes your layout has <slot name="head" /> inside <head>. If yours does not, add one, or render the component directly in the layout behind a prop such as localBusiness={true}. For the general pattern of JSON-LD in Astro, including Article and BreadcrumbList, see the Astro JSON-LD structured data guide.

Choosing the right LocalBusiness subtype

LocalBusiness works, but a subtype carries more meaning. Schema.org defines dozens. These are the ones that cover most small-business sites:

Business @type value Notes
Dentist, clinic Dentist, MedicalClinic, Physician MedicalBusiness is the parent
Law firm LegalService Attorney also exists
Accountant AccountingService Child of FinancialService
Plumber, electrician, roofer Plumber, Electrician, RoofingContractor Children of HomeAndConstructionBusiness
Restaurant, cafe Restaurant, CafeOrCoffeeShop Add servesCuisine, menu
Salon, spa HairSalon, DaySpa, BeautySalon Children of HealthAndBeautyBusiness
Real estate agency RealEstateAgent
Gym, yoga studio ExerciseGym, SportsActivityLocation

If nothing fits, use LocalBusiness or ProfessionalService and describe the work in description. A wrong specific type is worse than a correct general one.

Service-area businesses and multiple locations

A plumber who drives to customers often does not want a street address shown. In that case, omit streetAddress, keep addressLocality, addressRegion and postalCode, and add areaServed:

// src/data/business.ts (service-area variant, excerpt)
export const areaServed = [
  { '@type': 'City', name: 'Portland' },
  { '@type': 'City', name: 'South Portland' },
  { '@type': 'City', name: 'Westbrook' },
];

Spread areaServed into the schema object the same way as address. Only list places you actually serve and mention on the page.

For several locations, give each one its own page (/locations/portland/, /locations/bangor/) and its own LocalBusiness block with a unique @id. A Content Collection works well here. Each location is an entry with an address, hours and phone, and getStaticPaths() builds one page per entry. Link them back to the parent organisation with parentOrganization: { '@id': 'https://www.example.com/#org' }.

Validate LocalBusiness schema before shipping

Run three checks after npm run build:

  1. Open dist/index.html and confirm one application/ld+json script contains your business object. If it is empty or shows [object Object], you forgot JSON.stringify.
  2. Paste the deployed URL into Google’s Rich Results Test. It reports which properties Google recognises and flags missing required ones.
  3. Run the same URL through the Schema Markup Validator to catch schema.org vocabulary errors Google ignores.

Then compare the output with what a visitor sees. Hours in the schema that differ from the hours in the footer are a quality problem, not a technicality.

Fit it with the rest of your SEO head

LocalBusiness is one node in a larger picture. Your pages still need a title, description, canonical URL and Open Graph tags, plus a sitemap. The Astro SEO checklist covers those pieces. If you already output an Organization node, either replace it with the LocalBusiness node on business pages or connect the two with @id references inside one @graph so search engines do not see two unrelated entities.

If your page has a visible questions block, pair it with FAQ markup as shown in the Astro FAQ section with FAQPage schema.

Building for a clinic, law office or trade business and would rather start from finished pages, check the Astro themes for professional services or medical practices. Komal themes are plain Astro source, so the component above drops straight into their layouts.

FAQ

Does LocalBusiness schema improve local rankings?

Not directly. It helps search engines confirm your name, address, phone and hours, which supports the consistency local results depend on. Reviews, your Google Business Profile, relevance and proximity still matter more.

Where should LocalBusiness schema go on an Astro site?

Put it in the <head> of the home page and the contact or location page. For multi-location businesses, put one block per location page, each with its own @id, address and hours.

Can I use LocalBusiness schema without a street address?

Yes. Service-area businesses can omit streetAddress and describe coverage with areaServed. Keep the locality, region and postcode if they are accurate and shown on the site.

Should I use Microdata or JSON-LD in Astro?

Use JSON-LD. Google recommends it, it keeps markup separate from your HTML, and in Astro it is a single <script type="application/ld+json"> tag rendered at build time.

Do I need an Astro integration for structured data?

No. A small component with set:html={JSON.stringify(schema)} is enough. An integration adds dependencies without adding anything the component cannot do.