Hello, we apologize for the issue you are facing. To customize a LocalBusiness schema using theme functions and ACF (Advanced Custom Fields), you can define a new variable to get the value from the ACF field and use it in the Schema Generator. Here’s a general approach:
-
Add Custom Code to Your Theme: You will need to add a filter in your theme’s functions.php
file to modify the JSON-LD output for your LocalBusiness schema.
-
Use the rank_math/json_ld
Filter: This filter allows you to customize the JSON-LD data that Rank Math generates. Here’s an example of how you can implement this:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
// Check if you are on a specific location page
if ( is_singular('rm_locations') ) {
// Get ACF fields
$address = get_field('address');
$phone = get_field('phone');
$opening_hours = get_field('opening_hours');
// Customize the LocalBusiness schema
$data['@type'] = 'LocalBusiness';
$data['address'] = [
'@type' => 'PostalAddress',
'streetAddress' => $address,
'telephone' => $phone,
];
$data['openingHours'] = $opening_hours;
}
return $data;
}, 10, 2 );
-
Dynamic Data: Make sure that the ACF fields (address
, phone
, opening_hours
) are set up correctly in your WordPress admin for each location page. This way, each page will have its unique schema data based on the ACF values.
-
Testing: After implementing the code, test your pages using Google’s Structured Data Testing Tool to ensure that the schema is being generated correctly.
For more detailed guidance on using ACF with Rank Math, you can refer to our documentation on How to Use ACF Fields in Schema Generator.
If you have any further questions or need assistance, please reply to this ticket, and a human agent from our support team will assist you further!
Sources:
How to Use ACF Fields in Schema Generator » Rank Math
How to Use ACF Fields in Schema Generator » Rank Math
Another thing is, where not using rm_locations. We’re just using dynamic pages to show these location pages using ACF. So there are values in the ACF that we want to use in the LocalBusiness schema. Currently, the LocalBusiness schema for all the location pages that we is from the main/parent business, so all location pages has wrong address, phone, email, and other values.
What we want is to customize the LocalBusiness schema using custom functions that is able to dynamically populate/map the data from ACF to the schema.
Hello,
Thank you for your query and we are so sorry about the trouble this must have caused.
Configuring and Custom Schema Generator is only available in the PRO version, but your account seems to be under a free account. Can you please search and forward a receipt from FastSpring.com so we can locate your account?
Please check this article about the topic:
https://rankmath.com/kb/multiple-locations/#configuring-local-business-schema
https://rankmath.com/kb/schema-generator/
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.