Add a LocalBusiness Entity to Rank Math Schema
Adds a LocalBusiness node with your address, phone and hours to Rank Math's JSON-LD on the homepage, linked to the site's organization.
Opens WPIDE on
Code
// Your business details.
$wpide_rm_local = array(
'type' => 'LocalBusiness',
'phone' => '+1-555-010-0199',
'street' => '123 Main Street',
'city' => 'Springfield',
'region' => 'IL',
'zip' => '62701',
'country' => 'US',
'hours' => array( 'Mo-Fr 09:00-17:00' ),
);
add_filter( 'rank_math/json_ld', function ( $data ) use ( $wpide_rm_local ) {
if ( ! is_array( $data ) || ! is_front_page() ) {
return $data;
}
$data['wpideLocalBusiness'] = array(
'@type' => $wpide_rm_local['type'],
'@id' => home_url( '/#localbusiness' ),
'name' => get_bloginfo( 'name' ),
'url' => home_url( '/' ),
'telephone' => $wpide_rm_local['phone'],
'openingHours' => $wpide_rm_local['hours'],
'parentOrganization' => array( '@id' => home_url( '/#organization' ) ),
'address' => array(
'@type' => 'PostalAddress',
'streetAddress' => $wpide_rm_local['street'],
'addressLocality' => $wpide_rm_local['city'],
'addressRegion' => $wpide_rm_local['region'],
'postalCode' => $wpide_rm_local['zip'],
'addressCountry' => $wpide_rm_local['country'],
),
);
return $data;
}, 99 );
Notes
Rank Math PRO's Local SEO module does this too; use one or the other.
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.