v0lume/yii2-meta-tags DB based model meta data for SEO

extensionbehavioractiverecordseometametatags

yii2-meta-tags

DB based model meta data for SEO

screenshot

Installation

The preferred way to install this extension is through composer.

Either run

composer.phar require --prefer-dist v0lume/yii2-meta-tags "*"

or add

"v0lume/yii2-meta-tags": "*"

to the require section of your composer.json file.

Usage

Add MetaTagBehavior to your model, and configure it.


public function behaviors()
{
    return [
        'MetaTag' => [
            'class' => MetaTagBehavior::className(),
        ],
    ];
}

Add MetaTags somewhere in you application, for example in editing form.

echo MetaTags::widget([
    'model' => $model,
    'form' => $form
]);

Done! Now, you can get meta data of your current model:

echo $model->getBehavior('MetaTag')->title;
echo $model->getBehavior('MetaTag')->keywords;
echo $model->getBehavior('MetaTag')->description;

Or, by manually find model:

use v0lume\yii2\metaTags\model\MetaTag;

...

$meta_tag = MetaTag::findOne([
    'model_id' => $id,
    'model'  => (new \ReflectionClass($model))->getShortName()
]);

...

echo $meta_tag->title;
echo $meta_tag->keywords;
echo $meta_tag->description;

Auto registration meta tags

You can use MetaTagsComponent to perform auto registration meta tags

Configure MetaTagsComponent in main.php config:


...
'components' => [
    ...
    'metaTags' => [
        'class' => 'v0lume\yii2\metaTags\MetaTagsComponent',
        'generateCsrf' => false,
        'generateOg' => true,
    ],
    ...
],
...

And then, in your layouts or views or controller action

$model = \common\models\Page::findOne(['url' => '/']);

Yii::$app->metaTags->register($model);

If passed $model was attached MetaTagBehavior, component will register meta tags for that model. If MetaTagBehavior wasn't attached or model not passed, and generateCsrf is set to true, component will generate only csrf meta tags.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



v1.2.3 is the latest of 6 releases



MIT license
Stats
18 github stars & 9 github forks
0 downloads in the last day
6 downloads in the last 30 days
3845 total downloads