srg/laranx-seo

LaraNx SEO,Laravel网站的元标签管理

安装: 24

依赖项: 0

建议者: 0

安全: 0

星星: 13

关注者: 2

分支: 2

开放问题: 0

类型:

0.1.1 2022-01-11 14:44 UTC

This package is auto-updated.

Last update: 2024-09-11 20:42:24 UTC


README

LaraNx Seo可以让您的Laravel应用程序在数据库中存储SEO和社交媒体元标签数据,而不是在代码中。将营销数据从代码库移出并放入数据库,以便轻松修改。

LaraNx Seo创建标签节点并将它们与文件关联起来,然后在视图的头部渲染标签。

这是为那些需要将应用程序逻辑应用于SEO重要但无需在WordPress和Ghost等CMS软件中嵌入逻辑的公共页面而设计的完美解决方案。

此包和完整的LaraNx包非常适合Laravel网站的首页和主要页面,因为这些页面通常高度定制。

您还可以使用包的SEO部分为使用页面内容生成标签的页面(例如产品、书籍等)使用。

LaraNx SEO如何工作

创建标签

这是一个示例。您可以创建自己的CRUD资源或获取LaraNx完整版本

$tag = new Tag;
$tagData = [
    'page'                => 'about',             //identifier
    'title'               => 'about title',
    'description'         => 'about description',
    'canonical'           => 'https://example.com',
    'feature_image'       => 'https://example.com/images/feature.png',
    'og_title'            => '',                 //if blank render will use title
    'og_description'      => '',                 //if blank render will use description
    'og_image'            => '',                 //if blank render will use feature_image
    'twitter_title'       => '',                 //if blank render will use title
    'twitter_description' => '',                 //if blank render will use description
    'twitter_image'       => '',                 //if blank render will use feature_image
    'jsonld'              => '',                 //add validated jsonld string
];
$tag->store($tagData['page'], $tagData);

检索标签节点

在控制器中检索标签

$this->seo = new Seo;                    //this can be placed in constuctor
$this->seo->fill('about', 'Site Name');  //use page identifier and site name

//pass seo to view

页面内容以渲染SEO元标签

在控制器中检索模型

$product = Product::find($productId);

$seo = new Seo;                          //can be placed in constructor $this->seo                 
$seo->title($product->title);
$seo->description($product->description);
$seo->canonical('page-canonical');

$seo->opengraph('type', 'website');
$seo->opengraph('site_name', 'Site Name');
$seo->opengraph('title', $product->title);
$seo->opengraph('description', $product->description);
$seo->opengraph('url', 'page-canonical');
$seo->opengraphImage($product->imageUrl);

$seo->twitter('card', 'summary_large_image');
$seo->twitter('title', $product->title);
$seo->twitter('description', $product->description);
$seo->twitter('url', 'page-canonical');
$seo->twitter('image', $product->imageUrl);
            
//pass seo to view

输出元标签

layout.blade.php

<!doctype html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="/css/app.css" rel="stylesheet">
    {{-- SEO tags --}}
    {!! $seo->render() !!}
</head>
<body>
    <!-- ... -->
</body>
</html>

渲染的标签:渲染的标签!

想要一个包含管理界面、网站配置、网站标签回退和主题管理功能的完整营销解决方案?请考虑购买LaraNx Seo和主题管理!

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件