Really Dynamic JSON-LD

Developer
Size
2,659 Kb
Views
64,768

How do I make an really dynamic json-ld?

What is a really dynamic json-ld? How do you make a really dynamic json-ld? This script and codes were developed by UpBuild on 22 July 2022, Friday.

Really Dynamic JSON-LD Previews

Really Dynamic JSON-LD - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Really Dynamic JSON-LD</title>
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Really Dynamic JSON-LD - Script Codes JS Codes

// Here's the start of the standard "build dynamic JSON-LD scripts in GTM" function
(function() { // Here is where you can provide all the _easy_ data points. The ones that don't require advanced processing. // The variable bioData will be our source of truth and all the data points that are subject to change will ultimately be added to this variable. var bioData = { "@context": "http://schema.org", "@type": "Person", "name": "mike", "worksFor": "Michigan Auto Law" }; // Ref #1. Process AlumniOf // Gather all the schools and put them in an object variable var allSchools = document.querySelectorAll("[itemprop='alumniOf'] [itemprop='name']"); //Note - Since we've been seeing some sporadic issues with jQuery not behaving, I changed my original approach to leverage JavaScript's .querySelectorAll() method. For element selection, it works very well and won't fail if jQuery doesn't load in time. // If no schools are present, nothing else will happen here. The function below will not execute and alumniOf will not be added to the bioData variable. if (allSchools.length > 0) { // Declare a new Array varialbe to hold all the processed school data var theSchools = []; // Use jQuery's .each() method to iterate over all found schools for (var i = 0; i < allSchools.length; i++) { // convert the school's name into a text string and assign to a variable var schoolName = jQuery("[itemprop='alumniOf'] [itemprop='name']").eq(i).text().split(",", 1).toString(); // create an array variable called "injectable" that we can populate with the data on the current school. var injectable = { // Required static infomration that's the same for all schools "@type": "educationalOrganization", // Set the name of the school the the processed schoolName name: schoolName }; // push the injectable from this iteration of the function into the final "theSchools" array. theSchools.push(injectable); } // push "theSchools" into the "bioData" array and set it as the value of the "alumniOf" key. alumniOf didn't exist prior to this step, but because we push the school's info in using dot notation, it's automatically created as the location where that data is to be stored. bioData.alumniOf = theSchools; } // Ref #2. Process memberOf /* Copy entire code block from Ref #1 and modify as needed for the next 0-1-or-infinite data point. */ // Ref #3. Process affiliation /* Copy entire code block from Ref #1 and modify as needed for the next 0-1-or-infinite data point. */ // Chris Goddard magic var script = document.createElement('script'); script.type = "application/ld+json"; script.innerHTML = JSON.stringify(bioData); document.getElementsByTagName('head')[0].appendChild(script);
})(document);
Really Dynamic JSON-LD - Script Codes
Really Dynamic JSON-LD - Script Codes
Home Page Home
Developer UpBuild
Username upbuild
Uploaded July 22, 2022
Rating 3
Size 2,659 Kb
Views 64,768
Do you need developer help for Really Dynamic JSON-LD?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

UpBuild (upbuild) Script Codes
Create amazing love letters with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!