Really Dynamic JSON-LD
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 - 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);
Developer | UpBuild |
Username | upbuild |
Uploaded | July 22, 2022 |
Rating | 3 |
Size | 2,659 Kb |
Views | 64,768 |
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!
Name | Size |
SEO Model - Desktop Page Head - VPP | 3,038 Kb |
Simple Reviews JSON Variables | 1,616 Kb |
HTML Sitemap | 6,135 Kb |
Simple Reviews In-Line | 1,525 Kb |
Pardot Event Tracking Script 1 | 1,386 Kb |
NewPath | 1,557 Kb |
Simple - Organization Homepage Markup | 2,612 Kb |
Embed GIPHY Responsively | 1,394 Kb |
Blog Post 3 | 1,292 Kb |
Simple JSON Blog Post | 1,620 Kb |
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!
Name | Username | Size |
Process Accordion | Devilskitchen | 31,432 Kb |
Bootstrap Carousel Fade Transition | Rowno | 2,484 Kb |
After America | Jonathangarner | 2,686 Kb |
Learning canvas drawing | Aurer | 2,204 Kb |
The Walking Raymarcher | Xorxor_hu | 7,934 Kb |
Flower expansion | Sreucherand | 3,425 Kb |
Clock Face Idea | Chrisburnell | 3,196 Kb |
Simple jQuery Slider | Jurbank | 2,874 Kb |
Simple star rating using js and data-uri | TheEnd | 5,795 Kb |
Simple search using AngularJS | Haykou | 1,802 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!