PHP Classes

PHP Generate Json LD: Generate metadata for HTML pages in JSON-LD format

Recommend this page to a friend!
  Info   View files Example   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 182 This week: 2All time: 8,654 This week: 67Up
Version License PHP version Categories
jsonld 1.1.0Freely Distributable7.4HTML, PHP 5, SEO
Description 

Author

This package can generate metadata for HTML pages in JSON LD format.

It provides several classes that can be used to set properties of metadata values to be associated to the current Web pages.

The package can generate HTML tags in JSON LD format to be outputted within the current HTML page HEAD section.

Currently the package includes classes specialized in generating JSON LD metadata for pages that are articles, events or local businesses.

Innovation Award
PHP Programming Innovation award nominee
May 2020
Number 3
JSON-LD is a format of metadata that can be embedded in a Web page. It makes it easier easier to extract and process Web page metadata by external applications, like for instance search engines.

That metadata allows those external applications understand better what those pages are about, as well have more details about the pages that may not be visible to human users.

This package simplifies the process of generating metadata to be embedded in Web pages in JSON-LD format.

Manuel Lemos
Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler is available for providing paid consulting. Contact Stefan Kientzler .
Classes: 18 packages by
Country: Germany Germany
Age: 56
All time rank: 76649 in Germany Germany
Week rank: 11 Up1 in Germany Germany Up
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

Example

<?php
use SKien\JsonLD\JsonLD;
use
SKien\JsonLD\JsonLDLocalBusiness;

require_once
'autoloader.php';

$oJsonLD = new JsonLDLocalBusiness('FoodEstablishment'); // 'SportsActivityLocation');
$oJsonLD->setURL('https://www.mydomain.de');
$oJsonLD->setInfo('Sportsclimbing SC', 'info@mydomain.de', '12345 67890');
$oJsonLD->setDescription('Sportsclimbinbg indoor and outdoor for everyone');
$oJsonLD->setAddress('Street 12', '12345', 'MyTown', '', 'Germany');
$oJsonLD->setLocation('Sportsclimbing SC', 48.3365629, 7.8447896, 'https://www.google.de/maps/place/DAV-Kletterzentrum+Lahr/@48.3365629,7.8447896,156m/data=!3m1!1e3!4m5!3m4!1s0x47912e4949b57841:0xc26f08dacee0a1a9!8m2!3d48.3367173!4d7.8441243');
$oJsonLD->setLogo('elephpant.png');
$oJsonLD->addImage('elephpant.png'); // usually you should use a bigger image - only for test purposes to avoid warning from test tool
$oJsonLD->addLanguage('de');
$oJsonLD->setPriceRange('???');
$oJsonLD->setProperty('menu', 'https://www.mydomain.de/menucard', JsonLD::URL);
$oJsonLD->addOpeningHours([1,1,1,1,1,0,0], '8:00', '12:00');
$oJsonLD->addOpeningHours([1,1,0,0,1,0,0], '13:00', '17:30');

// and create department...
$oDepartment = new JsonLDLocalBusiness('Organization', true);
// at least the @id MUST be other than the base-id!
$oDepartment->setURL('https://www.mydomain.de/outdoor');
$oDepartment->setInfo('Sportsclimbing SC - Outdoor Center', 'outdoor@mydomain.de');
$oDepartment->setAddress('Another street', '12345', 'MyTown');

$oJsonLD->addDepartment($oDepartment);
?>
<!DOCTYPE html>
<html>
<head>
<title>Json LD Generator</title>
<!-- insert the tag in the head section of the document -->
<?php echo $oJsonLD->getHTMLHeadTag(false);?>
</head>
<body>
    <h1>Json LD Generator - Local Business</h1>
    <p>You can copy generated JsonLD script to test it in
        <a target="_blank" href="https://search.google.com/structured-data/testing-tool">
            https://search.google.com/structured-data/testing-tool
        </a>
    </p>
    <textarea style="font-family: 'Courier'; width: 100%; white-space: nowrap;" rows="50" spellcheck="false"><?php echo $oJsonLD->getJson(true);?></textarea>
</body>
</html>




  Files folder image Files  
File Role Description
Files folder imageSKien (2 directories)
Accessible without login Plain text file ArticleTest.php Example Example script
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file BusinessTest.php Example Example script
Accessible without login Plain text file clover.xml Data Auxiliary data
Accessible without login Image file elephpant.png Icon Icon image
Accessible without login Plain text file EventTest.php Example Example script
Accessible without login Plain text file githubwiki.xml Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file readme.md Doc. readme

  Files folder image Files  /  SKien  
File Role Description
Files folder imageJsonLD (4 files)
Files folder imageTest (1 directory)

  Files folder image Files  /  SKien  /  JsonLD  
File Role Description
  Plain text file JsonLD.php Class Class source
  Plain text file JsonLDArticle.php Class Class source
  Plain text file JsonLDEvent.php Class Class source
  Plain text file JsonLDLocalBusiness.php Class Class source

  Files folder image Files  /  SKien  /  Test  
File Role Description
Files folder imageJsonLD (5 files)

  Files folder image Files  /  SKien  /  Test  /  JsonLD  
File Role Description
  Plain text file JsonLDArticleTest.php Class Class source
  Plain text file JsonLDEventTest.php Class Class source
  Plain text file JsonLDLocalBusinessTest.php Class Class source
  Plain text file JsonLDTest.php Class Class source
  Plain text file JsonLDTestCase.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:182
This week:2
All time:8,654
This week:67Up