Dear All, I'm a novice but I have acquired a trusty friend in ChatGpt, and together, and I mean together, because this took hours, we found this solution. My stats for accessibility rose from 43 to 92 after applying this, thought I'd share the love... I hope it helps... please bare in my I am no expert and do all the necessary check you need to to ensure it doesn't impact negatively elsewhere. This code goes in Footer of Code injection. Be sure to put in your own business info in the relevant places:
<script>
document.addEventListener("DOMContentLoaded", function() {
var elements = document.querySelectorAll('script[type="application/ld+json"]');
elements.forEach(function(element) {
try {
var jsonData = JSON.parse(element.innerHTML);
// Update LocalBusiness schema
if (jsonData['@type'] === 'LocalBusiness') {
if (!jsonData.name || jsonData.name === "") {
jsonData.name = "YOUR BUSINESS NAME";
}
if (!jsonData.url || jsonData.url === "") {
jsonData.url = "https://www.business.com";
}
if (!jsonData.logo || jsonData.logo === "") {
jsonData.logo = "URL of your logo";
}
if (!jsonData.address || jsonData.address === "") {
jsonData.address = {
"@type": "PostalAddress",
"addressLocality": "Region",
"addressRegion": "Region code",
"postalCode": "Postal code",
"streetAddress": "Street",
"addressCountry": "Country code"
};
}
if (!jsonData.telephone || jsonData.telephone === "") {
jsonData.telephone = "telephone number";
}
if (!jsonData.priceRange || jsonData.priceRange === "") {
jsonData.priceRange = "your currency symbol";
}
if (!jsonData.currenciesAccepted || jsonData.currenciesAccepted === "") {
jsonData.currenciesAccepted = "your currency code";
}
if (!jsonData.paymentAccepted || jsonData.paymentAccepted === "") {
jsonData.paymentAccepted = "Credit Card";
}
if (!jsonData.openingHoursSpecification || jsonData.openingHoursSpecification.length === 0) {
jsonData.openingHoursSpecification = [
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
],
"opens": "09:00",
"closes": "17:00"
},
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Saturday"
],
"opens": "10:00",
"closes": "14:00"
}
];
}
element.innerHTML = JSON.stringify(jsonData);
}
// Update Organization schema
if (jsonData['@type'] === 'Organization') {
if (!jsonData.legalName || jsonData.legalName === "") {
jsonData.legalName = "Business legal name";
}
element.innerHTML = JSON.stringify(jsonData);
}
} catch (e) {
console.error("Error parsing JSON-LD: ", e);
}
});
});
</script>