yii2-jsonld-helper Yii2 helper class for registering structured data markup in JSON-LD format

yii2-jsonld-helper

  1. Resources
  2. Installation
  3. Sample Usage
  4. License

Yii2 helper class for registering structured data markup in JSON-LD format.

Resources

Installation

Composer

Add extension to your composer.json and update your dependencies as usual, e.g. by running composer update ~~~ [java] {

"require": {
    "nirvana-msu/yii2-jsonld-helper": "1.0.*@dev"
}

} ~~~

Sample Usage

To let search engines know how to display your website name in search results, you can add the following JSON-LD document somewhere on your landing page:

$doc = (object)[
    "@type" => "http://schema.org/WebSite",
    "http://schema.org/name" => Yii::$app->params['brand'],
    "http://schema.org/url" => Yii::$app->urlManager->hostInfo
];

JsonLDHelper::add($doc);

You can also use JsonLDHelper::addBreadcrumbList to add BreadcrumbList schema.org markup based on the application view breadcrumbs parameter. E.g. in the beginning of your layout add:

JsonLDHelper::addBreadcrumbList();

Finally, you must invoke JsonLDHelper::registerScripts method in the <head> section of your layout, e.g.

[xml]
<head>
    <!-- ... -->
    <?php JsonLDHelper::registerScripts(); ?>
    <?php $this->head() ?>
</head>

License

Extension is released under MIT license.

0 0
2 followers
0 downloads
Yii Version: 2.0
License: MIT
Category: Web Service
Developed by: Nirvana
Created on: Aug 22, 2016
Last updated: a year ago

Related Extensions