For do that we will make a Helper:
Create the file frontend/components/OpenGraph.php
<?php namespace frontend\components; use Yii; class OpenGraph { public static function generate($properties) { foreach($properties as $item => $value) { Yii::$app->view->registerMetaTag([ 'property' => $item, 'content' => $value, ]); } } }
In your controller or view:
use frontend\components\OpenGraph; OpenGraph::generate( [ 'og:site_name' => 'your site name', 'og:title' => 'your title', 'og:description' => 'your description', 'og:image' => 'your image', 'og:url' => 'your url', ] );
It’s done
You can add all properties you need, see the list here
Comments
Write comments