7
7
8
8
![ laravel-seo] ( https://repository-images.githubusercontent.com/845966143/6ff7437c-852d-41eb-8b2f-927551506a13 )
9
9
10
- This package offers an extremely flexible and advanced way to manage all of your SEO tags. Unlike other packages that focus on the most basic and common tags, this one implements all the protocols.
10
+ This package offers an extremely flexible and advanced way to manage all of your SEO tags.
11
11
12
12
With this package, you will be able to implement:
13
13
@@ -36,63 +36,135 @@ This is the content of the published config file:
36
36
``` php
37
37
return [
38
38
39
- /*
40
- |--------------------------------------------------------------------------
41
- | Default Title
42
- |--------------------------------------------------------------------------
43
- |
44
- | This is the default value used for <title >, "og:title", "twitter:title"
45
- |
46
- */
47
- 'title' => env('APP_NAME', 'Laravel'),
48
-
49
- /*
50
- |--------------------------------------------------------------------------
51
- | Default Description
52
- |--------------------------------------------------------------------------
53
- |
54
- | This is the default value used for <meta name =" description" >, <meta property =" og:description" >, <meta name =" twitter:description" >
55
- |
56
- */
57
- 'description' => null,
58
-
59
- /*
60
- |--------------------------------------------------------------------------
61
- | Default Image path
62
- |--------------------------------------------------------------------------
63
- |
64
- | This is the default value used for <meta property =" og:image" >, <meta name =" twitter:image" >
65
- | You can use relative path like "/opengraph.png" or url like "https://example.com/opengraph.png"
66
- |
67
- */
68
- 'image' => null,
69
-
70
- /*
71
- |--------------------------------------------------------------------------
72
- | Default Robots
73
- |--------------------------------------------------------------------------
74
- |
75
- | This is the default value used for <meta name =" robots" >
76
- | See Google documentation here: https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag?hl=fr#directives
77
- |
78
- */
79
- 'robots' => 'max-snippet:-1,max-image-preview:large,max-video-preview:-1',
80
-
81
- /*
82
- |--------------------------------------------------------------------------
83
- | Default Sitemap path
84
- |--------------------------------------------------------------------------
85
- |
86
- | This is the default value used for <link rel =" sitemap" >
87
- | You can use relative path like "/sitemap.xml" or url like "https://example.com/sitemap.xml"
88
- |
89
- */
90
- 'sitemap' => null,
39
+ 'defaults' => [
40
+ /*
41
+ |--------------------------------------------------------------------------
42
+ | Default Title
43
+ |--------------------------------------------------------------------------
44
+ |
45
+ | This is the default value used for <title >, "og:title", "twitter:title"
46
+ |
47
+ */
48
+ 'title' => env('APP_NAME', 'Laravel'),
49
+
50
+ /*
51
+ |--------------------------------------------------------------------------
52
+ | Default Description
53
+ |--------------------------------------------------------------------------
54
+ |
55
+ | This is the default value used for <meta name =" description" >, <meta property =" og:description" >, <meta name =" twitter:description" >
56
+ |
57
+ */
58
+ 'description' => null,
59
+
60
+ /*
61
+ |--------------------------------------------------------------------------
62
+ | Default Keywords
63
+ |--------------------------------------------------------------------------
64
+ |
65
+ | This is the default value used for <meta name =" keywords" >
66
+ | Type supported: string or array of strings
67
+ |
68
+ */
69
+ 'keywords' => null,
70
+
71
+ /*
72
+ |--------------------------------------------------------------------------
73
+ | Default Image path
74
+ |--------------------------------------------------------------------------
75
+ |
76
+ | This is the default value used for <meta property =" og:image" >, <meta name =" twitter:image" >
77
+ | You can use relative path like "/opengraph.png" or url like "https://example.com/opengraph.png"
78
+ |
79
+ */
80
+ 'image' => null,
81
+
82
+ /*
83
+ |--------------------------------------------------------------------------
84
+ | Default Robots
85
+ |--------------------------------------------------------------------------
86
+ |
87
+ | This is the default value used for <meta name =" robots" >
88
+ | See Google documentation here: https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag?hl=fr#directives
89
+ |
90
+ */
91
+ 'robots' => 'max-snippet:-1,max-image-preview:large,max-video-preview:-1',
92
+
93
+ /*
94
+ |--------------------------------------------------------------------------
95
+ | Default Sitemap path
96
+ |--------------------------------------------------------------------------
97
+ |
98
+ | This is the default value used for <link rel =" sitemap" >
99
+ | You can use relative path like "/sitemap.xml" or url like "https://example.com/sitemap.xml"
100
+ |
101
+ */
102
+ 'sitemap' => null,
103
+ ],
104
+
105
+ /**
106
+ * @see https://ogp.me/
107
+ */
108
+ 'opengraph' => [
109
+ /*
110
+ |--------------------------------------------------------------------------
111
+ | Default Site Name
112
+ |--------------------------------------------------------------------------
113
+ |
114
+ | This is the default value used for <meta property =" og:site_name" />
115
+ | If null: config('app.name') is used.
116
+ |
117
+ */
118
+ 'site_name' => null,
119
+
120
+ /*
121
+ |--------------------------------------------------------------------------
122
+ | Default Determiner
123
+ |--------------------------------------------------------------------------
124
+ |
125
+ | This is the default value used for <meta property =" og:determiner" />
126
+ | Possible values are: a, an, the, "", auto
127
+ |
128
+ */
129
+ 'determiner' => '',
130
+ ],
131
+
132
+ /**
133
+ * @see https://developer.x.com/en/docs/x-for-websites/cards/overview/abouts-cards
134
+ */
135
+ 'twitter' => [
136
+ /*
137
+ |--------------------------------------------------------------------------
138
+ | Default Twitter username
139
+ |--------------------------------------------------------------------------
140
+ |
141
+ | This is the default value used for <meta name =" twitter:site" />
142
+ | Example: @X
143
+ |
144
+ */
145
+ 'site' => null,
146
+ ],
147
+
148
+ /**
149
+ * @see https://schema.org/WebPage
150
+ */
151
+ 'schema' => [
152
+ /*
153
+ |--------------------------------------------------------------------------
154
+ | Default WebPage schema
155
+ |--------------------------------------------------------------------------
156
+ |
157
+ | This is the default value used for the schema WebPage
158
+ | @see https://schema.org/WebPage for all available properties
159
+ |
160
+ */
161
+ 'defaults' => [],
162
+ ],
91
163
92
164
];
93
165
```
94
166
95
- ## Usage
167
+ ## Introduction
96
168
97
169
You can display all the SEO tags in your view simply by calling the ` seo ` function like this:
98
170
@@ -102,29 +174,52 @@ You can display all the SEO tags in your view simply by calling the `seo` functi
102
174
</head >
103
175
```
104
176
105
- This function accepts different kinds of arguments, allowing you to take full control over your SEO.
106
-
107
- ### Basic SEO
177
+ This will render all the default tags:
178
+
179
+ ``` html
180
+ <title >Home</title >
181
+ <meta name =" robots" content =" '.$robots.'" />
182
+ <link
183
+ rel =" canonical"
184
+ href =" max-snippet:-1,max-image-preview:large,max-video-preview:-1"
185
+ />
186
+ <!-- opengraph -->
187
+ <meta property =" og:title" content =" Laravel" />
188
+ <meta property =" og:url" content =" https://exemple.com" />
189
+ <meta property =" og:locale" content =" en" />
190
+ <meta property =" og:site_name" content =" Laravel" />
191
+ <meta property =" og:type" content =" website" />
192
+ <!-- twitter / X -->
193
+ <meta name =" twitter:card" content =" summary" />
194
+ <meta name =" twitter:title" content =" Laravel" />
195
+ <!-- JSON+LD -->
196
+ <script type =" application/ld+json" >
197
+ {
198
+ " @context" : " https://schema.org" ,
199
+ " @type" : " WebPage" ,
200
+ " name" : " Home" ,
201
+ " url" : " https://example.com"
202
+ }
203
+ </script >
204
+ ```
108
205
109
- The simplest way to define your SEO tags is with ` Elegantly\Seo\SeoData::class ` .
110
- This class provides a unified representation of the most common SEO tags (Open Graph, Twitter, etc.).
111
- It will also use the defaults defined in your config.
206
+ ### Basic Usage
112
207
113
208
#### From a Controller
114
209
115
- Define a ` SeoData ` object and pass it to the view:
210
+ Most of the time, your will want to define you seo tags from a controller
116
211
117
212
``` php
118
213
namespace App\Http\Controllers;
119
214
120
- use Elegantly\Seo\SeoData ;
215
+ use \ Elegantly\Seo\SeoManager ;
121
216
122
217
class HomeController extends Controller
123
218
{
124
219
function __invoke()
125
220
{
126
221
return view('home', [
127
- 'seo' => new SeoData (
222
+ 'seo' => SeoManager::default (
128
223
title: "Homepage",
129
224
)
130
225
]);
0 commit comments