How to Add Yoast Local SEO Data with PHP to a Location Page

Updated January 24, 2024
~ minute read
add toast local SEO Data

Content Key

Share this Post :
Get the most out of your marketing
Join over 100,000 of the most intelligent marketers in the galaxy, and receive marketing news and insights straight to your inbox.
Enter Email to Get Started:
(We will never share your information.)

add toast local SEO Data

Add Yoast Local SEO Data to a Location Page using PHP: In this article, I am going to teach you how to add Yoast Local SEO Data to a Location Page. By adding this data, your location pages will rank higher on Google and other search engines.

Web development is sometimes (always) challenging; we’ve found the Yoast Local SEO shortcodes can be limiting at times. We still use their data but have to pull it into very specific places on the site. The WordPress function` get_options()` is how you go about getting the local business data when using a single location (doesn’t work with multiple locations).

The major reason for using the Yoast Local SEO plugin is because the output is on point with schema and HTML markup. If you use the above and don’t take into account schema and html, then you will miss out on one of the best benefits of this plugin.  That’s how Google determines position in its Local rankings results.

Step 1: Get Local SEO Data from the Database

Yoast stores your single location data as a serialized array in the options table for WordPress.

In order to retrieve that data, set a custom variable as an array:

1
$wpseo_local = get_option('wpseo_local');

Need help with your News Website SEO Strategy? Schedule a free strategy session with the 702 Pros team.

Get a Free Digital Marketing Quote!
Want to talk now?
Give us a call at (702) 904-4262

Powered by OnSago

Rank #1 on google with 702 pros seo - digital
Rank #1 on google with 702 pros seo

 

Step 2: Find What Data You Need from the Database

(Add Yoast Local SEO Data to a Location Page using PHP) After the $wpseo local variable is setup as an array storing all of the Yoast Local SEO data, it has been really easy to use that information with any of the following fields:

Below is a list of PHP calls to get you started in the right direction. Feel free to copy the information below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?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: Setting the Time Format Correctly

As a standard, your business opening hours will be stored in military time (ie, 0900 is 9:00 am, and 1300 is 1:00 pm). You will most likely want to convert them from military to a 12-hour format.
You can easily do so by using a time variable like the one below:

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

Step 4: Removing Special Characters from Phone Numbers

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

1
<a href="tel:7029044262">(702) 904-4242</a>

However, when using Yoast fields, the inherit data will automatically pull special characters into the HTML (ie: ‘(‘ and ‘-‘) which will mess with your HTML code a bit, ultimately making your phone links not work correctly.

Example below:

1
<a href="tel:(702) 904-4242">(702) 904-4242</a>

To fix this, you’ll u need to use a regex call to strip and remove unwanted characters from the link.

In PHP this is called a preg_replace action and looks like this:

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

I hope this article has helped you in creating PHP data calls for Local SEO data from Yoast. If you have any questions, please leave a comment below. This guide is also available and written as a blog post. You can find the blog post here. Check out the Multi-location Yoast SEO Guide to learn how to add data for more than one location. Step-by-Step tutorial you will need to edit a few different files in order to add Yoast SEO data to your location page.

Need help with your News Website SEO Strategy? Schedule a free strategy session with the 702 Pros team.

Get a Free Digital Marketing Quote!
Want to talk now?
Give us a call at (702) 904-4262

Powered by OnSago

Rank #1 on google with 702 pros seo - digital
Rank #1 on google with 702 pros seo

 

Common Yoast Local SEO Questions:

  1. Q: What does Yoast local SEO do?

    A: The Local SEO plugin helps you to embed Google Maps and automatically show your up-to-date opening hours. All you need is a Google account and no technical knowledge.

  2. Q: Does Yoast SEO Really Work?

    A: Yes, Yoast SEO works! It’s the most popular plugin on WordPress, with over 11 million downloads and a 5-star rating. You don’t stay that popular for so long if you don’t have something to show for it 🌟

  3. Q: Is Yoast SEO free worth?
    A: Is Yoast SEO Premium worth it? No, it is not. The multiple focus keywords feature is pretty much useless, redirects can be setup using free redirect plugins, and nothing in Yoast Premium directly improves your SEO. It’s not worth $99/year.
  4. Q: What is better than Yoast SEO?
  5. Q: What is the difference between organic SEO and local SEO?
  6. Q: How much is local SEO?
  7. Q: What is meant by local SEO?
  8. Q: How does local SEO work?
  9. Q: How can I improve my local SEO?
  10. Q: What is local SEO for small business?
  11. Q: What is White Hat SEO?
  12. Q: What are the types of SEO?
  13. Q: What is organic SEO?
  14. Q: What is off-page SEO?
  15. Q: How do you do eCommerce SEO?
  16. Q: What is mobile SEO?

Other Interesting Reads:

Related Terms:

Other Considerations:

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

add toast local SEO Data

 

Leave a Reply

More Great Posts

Advertise with us
Join our advertising network to grow your business. Give us a call at (702) 904-4262
34.99 WordPress Updates | WordPress Support by 702 Pros
Sponsored
Kyla Sloan | Kyla Estes | Client Management | Reception | Sales
Advertising with Us
Kyla SloanAdvertising Specialist
Our team has the digital and traditional marketing skills to get you in front of customers looking for your product or service.
Want to talk now? Give us a call at (702) 904-4262

Powered by OnSago

Add Your Business To the 702 Pros' Directory
Please add some general information about your business.
Want to talk now? Give us a call at (702) 904-4262

Powered by OnSago

2022 Sale

Get 20% off!

All Web Design Packages
Days
Hours
Minutes
Seconds
Want to talk now? Give us a call at (702) 904-4262

Powered by OnSago