ryhor123/yii2-seotools

组件和模块,用于管理页面的独特SEO标题、描述、h1标题和与页面关联的独特文本

安装: 323

依赖项: 0

建议者: 0

安全: 0

类型:yii2-extension

dev-master 2021-11-17 11:22 UTC

This package is auto-updated.

Last update: 2023-10-29 02:22:43 UTC


README

如果您需要设置与页面关联的独特SEO标题和描述,这个扩展就是您需要的,您还可以使用WYSIWYG工具添加加粗和链接,以改进具有独特内容的页面的SEO。

使用模块设置这些字段以管理所有这些功能。

内部使用md5哈希生成唯一ID,以(主机 + 路径)识别页面和yii缓存系统,并标记依赖项以提高速度。

安装

安装此扩展的首选方式是通过 composer

运行以下命令

php composer.phar require --prefer-dist ryhor123/yii2-seotools "*"

或者

"ryhor123/yii2-seotools": "*"

将其添加到您的 composer.json 文件的require部分。

迁移

在终端中运行以下命令进行数据库迁移

Linux/Unix

yii migrate/up --migrationPath=@vendor/ryhor123/yii2-seotools/migrations

Windows

yii.bat migrate/up --migrationPath=@vendor/ryhor123/yii2-seotools/migrations

配置

开启seotool组件的简单示例。

'components' => [
        'seotools' => [
            'class' => 'ryhor123\seotools\Component',
        ],
    ],

开启seotools模块

简单示例

    'modules' => [
        'seotools' => [
            'class' => 'ryhor123\seotools\Module',
            'roles' => ['@'], // For setting access levels to the seotools interface.
        ]
    ],

用法

安装扩展后,只需在您的代码中使用它

 // @param bool $setCanonical true, try to create a canonical url and og url, action needs to have params
 // @param bool $checkDb try to get from DB params, true: try to get info from DB if it doesn't find save a new field
 // associated to current host + '/' + path, false: it just set the params give in the call. The db params has priority
 // over the call function params. It does a merge
$setCanonical = false;
$checkDb = true;
Yii::$app->seotools->setMeta(['title' => \Yii::t('title','A good title for this page')], $setCanonical, $checkDb);

通过调用无效的缓存来保存记录

\yii\caching\TagDependency::invalidate(Yii::$app->cache, ryhor123\seotools\Component::CACHE_TAG);

URLs

seotools管理模块的URLs

/seotools/manage
/seotools/manage/create