Get Updates to Your Inbox!

When developing a custom site we’ve realized that the shortcodes provided by the Yoast Local SEO plugin are very limiting. We still like using their data but end up having to pull the data into very specific places on the site. Using the built-in WordPress function get_option, here is how to get the local business data when using a single location (does not work with multiple locations):

Disclaimer: Yoast Probably Outputs the Data Better than You

The major reason for using the Yoast Local SEO plugin is because the output is spot on with all the schema and html markup. If you use the above and don’t take the time to consider the schema and html you really are losing out on a huge reason to use this plugin. That’s the stuff Google reads for Local Rankings. Gotta have it.

Step 1: Call the Local Data from the Options Table

Yoast stores your single location data as a serialized array in the options table for WordPress. In order to retrieve that data, use the following to set a custom variable as an array:

$wpseo_local = get_option('wpseo_local');

Step 2: Specify which data field you want

Since you have already set up the $wpseo_local variable as an array storing all of the Yoast Local SEO data, you can now retrieve that data using any of the following fields:

<?php echo $wpseo_local['location_name']; ?>
<?php echo $wpseo_local['business_type']; ?>
<?php echo $wpseo_local['location_address']; ?>
<?php echo $wpseo_local['location_address_2']; ?>
<?php echo $wpseo_local['location_city']; ?>
<?php echo $wpseo_local['location_state']; ?>
<?php echo $wpseo_local['location_zipcode']; ?>
<?php echo $wpseo_local['location_country']; ?>
<?php echo $wpseo_local['location_phone']; ?>
<?php echo $wpseo_local['location_phone_2nd']; ?>
<?php echo $wpseo_local['location_fax']; ?>
<?php echo $wpseo_local['location_email']; ?>
<?php echo $wpseo_local['location_url']; ?>
<?php echo $wpseo_local['location_vat_id']; ?>
<?php echo $wpseo_local['location_tax_id']; ?>
<?php echo $wpseo_local['location_coc_id']; ?>
<?php echo $wpseo_local['location_price_range']; ?>
<?php echo $wpseo_local['location_coords_lat']; ?>
<?php echo $wpseo_local['location_coords_long']; ?>
<?php echo $wpseo_local['locations_slug']; ?>
<?php echo $wpseo_local['locations_label_singular']; ?>
<?php echo $wpseo_local['locations_label_plural']; ?>
<?php echo $wpseo_local['locations_taxo_slug']; ?>
<?php echo $wpseo_local['business_image']; ?>
<?php echo $wpseo_local['opening_hours_monday_from']; ?>
<?php echo $wpseo_local['opening_hours_monday_to']; ?>
<?php echo $wpseo_local['opening_hours_monday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_monday_second_to']; ?>
<?php echo $wpseo_local['opening_hours_tuesday_from']; ?>
<?php echo $wpseo_local['opening_hours_tuesday_to']; ?>
<?php echo $wpseo_local['opening_hours_tuesday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_tuesday_second_to']; ?>
<?php echo $wpseo_local['opening_hours_wednesday_from']; ?>
<?php echo $wpseo_local['opening_hours_wednesday_to']; ?>
<?php echo $wpseo_local['opening_hours_wednesday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_wednesday_second_to']; ?>
<?php echo $wpseo_local['opening_hours_thursday_from']; ?>
<?php echo $wpseo_local['opening_hours_thursday_to']; ?>
<?php echo $wpseo_local['opening_hours_thursday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_thursday_second_to']; ?>
<?php echo $wpseo_local['opening_hours_friday_from']; ?>
<?php echo $wpseo_local['opening_hours_friday_to']; ?>
<?php echo $wpseo_local['opening_hours_friday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_friday_second_to']; ?>
<?php echo $wpseo_local['opening_hours_saturday_from']; ?>
<?php echo $wpseo_local['opening_hours_saturday_to']; ?>
<?php echo $wpseo_local['opening_hours_saturday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_saturday_second_to']; ?>
<?php echo $wpseo_local['opening_hours_sunday_from']; ?>
<?php echo $wpseo_local['opening_hours_sunday_to']; ?>
<?php echo $wpseo_local['opening_hours_sunday_second_from']; ?>
<?php echo $wpseo_local['opening_hours_sunday_second_to']; ?>
<?php echo $wpseo_local['sl_num_results']; ?>
<?php echo $wpseo_local['unit_system']; ?>
<?php echo $wpseo_local['map_view_style']; ?>
<?php echo $wpseo_local['address_format']; ?>
<?php echo $wpseo_local['default_country']; ?>
<?php echo $wpseo_local['show_route_label']; ?>
<?php echo $wpseo_local['custom_marker']; ?>
<?php echo $wpseo_local['api_key_browser']; ?>
<?php echo $wpseo_local['api_key']; ?>
<?php echo $wpseo_local['location_taxo_slug']; ?>
<?php echo $wpseo_local['location_timezone']; ?>

Step 3: Changing Opening Hours from Military time to 12 hour

The opening hours are stored in military time. In order to convert them to a 12 hour format, use the following on any of the time variables:

<?php echo date("g:i a", strtotime($wpseo_local['opening_hours_sunday_from'])); ?>

Step 4: Removing Non-numeric Characters from Phone Number in Href

Most people are familiar with using the anchor tag for a phone number, the typical format is as follows:

<a href="tel:7027066366">(702) 706-6366</a>

The issue is that when you call in the number from the Yoast field, it will contain whatever non-numeric characters you have entered into the field for appearance purposes. You definitely want to leave that data in there, and you woudn’t want to have a secondary field. If you plug that number straight into the href of the anchor tag your site will not pass validation. It will look like this:

<a href="tel:(702) 706-6366">(702) 706-6366</a>

Those parenthesis, spaces and hyphens are the issue. In order to remove them, use this simple preg_replace:

<?php echo preg_replace("/[^0-9,.]/", "", $wpseo_local['location_phone']); ?>

Step 5: Protecting Email Addresses from Spam

One further step to take is to use the built in WordPress function antispambot to protect your email addresses from spam bots. It’s a really simple one to implement, here’s what it looks like:

<?php echo antispambot($wpseo_local['location_email']); ?>
More Information

Leave a Reply

Your email address will not be published. Required fields are marked *