LocalBusiness schema generator for WordPress
Fill in a business's name, address, phone and hours and get its LocalBusiness structured data, as a small WordPress plugin file or as the block alone, with the properties Google documents. Made in your browser; nothing is sent.
Google requires a name and an address. Still to fill in: the business's name and its address.
<?php
/**
* Plugin Name: Local business markup
* Description: Prints LocalBusiness structured data on the front page.
*
* Save this file as wp-content/mu-plugins/local-business-markup.php.
* Keep it the same as what the page shows a visitor.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action(
'wp_head',
function () {
if ( ! is_front_page() ) {
return;
}
$business = array(
'@context' => 'https://schema.org',
'@type' => 'LocalBusiness',
);
echo '<script type="application/ld+json">' . wp_json_encode( $business ) . '</script>' . "\n";
}
);
What the block is for
LocalBusiness structured data tells a search engine, in a form it can read without guessing, what a business is called, where it is, how to reach it and when it is open. Google's documentation requires two things in it, a name and an address, and lists the rest as recommended. It does not say the block moves a page up the results, and it says outright that structured data is no guarantee that anything extra is shown.
What the file holds
- Only the properties Google documents for a local business: the kind of business, its name and address, and, where you give them, a phone number, the address of its page, a price range, coordinates and opening hours.
- Only what you filled in. A field left empty, or one that is not what it should be, such as a phone number with no country code, adds nothing to the file.
- Hours as Google's documentation writes them. Days with the same hours share one entry. A day closed all day opens and closes at 00:00, which is how that documentation says to state it.
- No rating and no reviews. Google lists those for a site that collects reviews about other businesses, and says a business's own pages about itself are not eligible for review stars. Why the stars do not show for a local business has the rule.
How to use it
The plugin file goes in wp-content/mu-plugins/, a folder WordPress loads every file from without anything being activated. Create the folder if it is not there, upload the file, then open the page and look in its source for application/ld+json. Google's Rich Results Test reads the same page and says what it found. To change a detail later, edit it in the file.
The block alone can go in a Custom HTML block on the page. If an SEO plugin on the site already prints LocalBusiness data, fill in its settings instead, so the page does not carry two blocks that disagree. How to add local business schema to WordPress covers each property and how to check for a block that is already there.
What it does not do
It does not check that the details are true or that they match the page: that part is yours. Google's guidelines say not to mark up what a visitor cannot see, so the name, address, phone and hours in the file should be the ones the page shows, and the ones on the business's Google Business Profile. It writes one business. A business with several branches needs a block on each branch's own page.
Nothing leaves your browser. The file is built on this page, and nothing you type is sent or kept.
Common questions
Will this get my business into the map results?
Which page should carry it?
Why can't I add my star rating?
We go to our customers and show no street address. What do I put?
I already use an SEO plugin. Do I need this?
Rather have it set up for you?
Tell us the address of the site. We check what it already tells a search engine about the business, add what is missing and test it, and reply with a fixed quote first. The diagnosis is free.
Get a free diagnosis
