amirax/yii2-seo-tools

SEO tools for Yii 2 framework

Installs: 863

Dependents: 0

Suggesters: 0

Security: 0

Stars: 12

Watchers: 3

Forks: 3

Type:yii2-extension

v0.2.3 2017-06-13 14:43 UTC

This package is not auto-updated.

Last update: 2024-04-27 15:09:55 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require amirax/yii2-seo-tools "*"

or add

"amirax/yii2-seo-tools": "*"

to the require section of your composer.json file.

After installation extension run migration:

./yii migrate --migrationPath="@vendor/amirax/yii2-seo-tools/src/migrations"

Usage

SEO Meta

In components configuration add the following

'components' => [
    'seo' => [
        'class' => 'Amirax\SeoTools\Meta'
    ]
    ...
]

And add SEO extension to bootstrap

'bootstrap' => ['log', 'seo']

Extension will automatically load the correct row from the database using the currently running and params.You can optionally override data by specifying them in a parameter array

Yii::$app->seo->title = 'Page title';
Yii::$app->seo->metakeys = 'seo,yii2,extension';
Yii::$app->seo->metadesc = 'Page meta description';
Yii::$app->seo->tags['og:type'] = 'article';

You can set the templates for tags. For example:

Yii::$app->seo->setVar('USER_NAME', 'Amirax');
Yii::$app->seo->tags['og:title'] = 'Hello %USER_NAME%';

Default variables:

  • %HOME_URL% - Homepage url
  • %CANONICAL_URL% - Canonical URL for current page
  • %LOCALE% - Site locale

SEO Redirect

For enabling SEO Redirect add to configuration file

'errorHandler' => [
    'class' => 'Amirax\SeoTools\Redirect',
],