kaio Piola / seo
SEO 生成器
v1.1
2022-01-30 14:39 UTC
Requires
- php: ^7.4|^8.0
This package is auto-updated.
Last update: 2024-08-29 06:01:48 UTC
README
en-US
此插件正在开发中,使用时可能会出现意外行为,请在使用此解决方案时报告您遇到的任何错误或错误,以便我们可以使其尽可能适用于您!
SEO 插件是您网站的一个简单的 HTML SEO 生成器。该插件可以生成如以下示例中的元标签
<title>PAGE TITLE</title> <meta name="description" content="PAGE DESCRIPTION"> <meta name="keywords" content="TAG 1, TAG 2, ANOTHER TAG"> <meta property="og:title" content="PAGE TITLE" /> <meta property="og:type" content="" /> <meta property="og:site_name" content="" /> <meta property="og:url" content="http://yourwebsite.com/example" /> <meta property="og:image" content="http://yourwebsite.com/example" /> <meta property="og:description" content="PAGE DESCRIPTION" /> <meta property="og:locale" content="pt_BR" /> <meta property="twitter:title" content="PAGE TITLE" /> <meta property="twitter:description" content="PAGE DESCRIPTION" /> <meta property="twitter:image" content="" /> <meta property="twitter:url" content="http://yourwebsite.com/example" /> <meta property="twitter:card" content="summary" />
安装
首先,在您的项目中运行以下命令
composer require kaiopiola/seo
然后,在您想要加载插件的 PHP 文件中调用主类
use Kaiopiola\Seo\Seo;
SEO 插件如何工作
如何设置插件
要设置 SEO 插件,只需将类实例化到变量中,然后定义其配置参数,如下面的示例所示
# Instantiating class in a variable: $seo = new Seo; # Setting parameters: $seo->setMeta("title", "PAGE TITLE"); // Page title $seo->setMeta("description", "PAGE DESCRIPTION"); // Page description $seo->setMeta("tags", "TAG 1, TAG 2, ANOTHER TAG"); // Page keywords $seo->setMeta("image", "IMAGE URL"); // Main image to represent current page $seo->setMeta("locale", "LOCALE"); // Will use current detected locale if not set $seo->setMeta("url", "PAGE URL"); // Will use current page URL if not set $seo->setMeta("canonical", "CANONICAL URL"); // Will use "url" if not set # Optional - Facebook OpenGraph Settings $seo->setMeta("og_title", "OG TITLE"); // Will use "title" if not set $seo->setMeta("og_type", "OG TYPE"); // NULL if not set. Please check OpenGraph docs to fill this field $seo->setMeta("og_site_name", "OG SITENAME"); // OpenGraph site name. NULL if not set $seo->setMeta("og_url", "OG CANONICAL URL"); // OpenGraph canonical URL, will use "url" if not set $seo->setMeta("og_image", "OG IMAGE URL"); // Will use "image" if not set $seo->setMeta("og_description", "OG DESCRIPTION"); // Will use "description" if not set $seo->setMeta("og_locale", "OG LOCALE"); // Will use "locale" if not set // You can also set Open Graph values automatically, according to main Setting parameters, as below: $seo->autoSetOpengraph(); # Optional - Twitter Settings $seo->setMeta("twitter_title", "TWITTER TITLE"); // Will use "title" if not set $seo->setMeta("twitter_description", "TWITTER DESCRIPTION"); // Will use "description" if not set $seo->setMeta("twitter_image", "TWITTER IMAGE URL"); // Will use "image" if not set $seo->setMeta("twitter_url", "TWIITER CANONICAL URL"); // Twitter canonical URL, will use "url" if not set $seo->setMeta("twitter_card", "TWITTER CARD TYPE"); // Twitter Card type, will use SUMMARY by default if not set // You can also set Twitter values automatically, according to main Setting parameters, as below: $seo->autoSetTwitter(); # Render the values $seo->render();
渲染值放置在哪里?
您必须在 HTML 代码的相应部分放置渲染结果,如下面的示例所示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <?= $seo->render(); ?> </head> <body> <h1>Example</h1> </body> </html>
注意事项
本项目欢迎各种贡献,无论是建议还是对任何代码的改进。请自由参与其开发。
许可证
MIT 许可证 (MIT)。请阅读 许可证文件 了解更多信息。