SEO Tools for Laravel
</a>
<h1 align="center">SEOTools - SEO Tools for Laravel and Lumen</h1>
<br>
SEOTools is a package for Laravel 5.8+ and Lumen that provides helpers for some common SEO techniques.
For license information check the LICENSE-file.
The first step is using composer to install the package and automatically update your composer.json file, you can do this by running:
composer require artesaos/seotoolsNote: If you are using Laravel 5.5, the steps 2 and 3, for providers and aliases, are unnecessaries. SEOTools supports Laravel new Package Discovery.
You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your config/app.php file adding the following code at the end of your 'providers' section:
Note: If you are using Laravel 11+, you will have to update
bootstrap/providers.phpinstead. Package Discovery.
config/app.php
<?php
return [
// ...
'providers' => [
Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class,
// ...
],
// ...
];Go to /bootstrap/app.php file and add this line:
<?php
// ...
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
// ...
$app->register(Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class);
// ...
return $app;Note: facades are not supported in Lumen.
You may get access to the SEO tool services using following facades:
Artesaos\SEOTools\Facades\SEOMetaArtesaos\SEOTools\Facades\OpenGraphArtesaos\SEOTools\Facades\TwitterCardArtesaos\SEOTools\Facades\JsonLdArtesaos\SEOTools\Facades\JsonLdMultiArtesaos\SEOTools\Facades\SEOToolsYou can setup a short-version aliases for these facades in your config/app.php file. For example:
<?php
return [
// ...
'aliases' => [
'SEOMeta' => Artesaos\SEOTools\Facades\SEOMeta::class,
'OpenGraph' => Artesaos\SEOTools\Facades\OpenGraph::class,
'Twitter' => Artesaos\SEOTools\Facades\TwitterCard::class,
'JsonLd' => Artesaos\SEOTools\Facades\JsonLd::class,
'JsonLdMulti' => Artesaos\SEOTools\Facades\JsonLdMulti::class,
// or
'SEO' => Artesaos\SEOTools\Facades\SEOTools::class,
// ...
],
// ...
];In your terminal type
php artisan vendor:publishor
php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider"Lumen does not support this command, for it you should copy the file
src/resources/config/seotools.phptoconfig/seotools.phpof your project
In seotools.php configuration file you can determine the properties of the default values and some behaviors.
defaults - What values are displayed if not specified any value for the page display. If the value is false, nothing is displayed.webmaster - Are the settings of tags values for major webmaster tools. If you are null nothing is displayed.defaults - Are the properties that will always be displayed and when no other value is set instead. You can add additional tags that are not included in the original configuration file.defaults - Are the properties that will always be displayed and when no other value is set instead. You can add additional tags that are not included in the original configuration file.defaults - Are the properties that will always be displayed and when no other value is set instead. You can add additional tags that are not included in the original configuration file.Note: facades are not supported in Lumen.
<?php
$seotools = app('seotools');
$metatags = app('seotools.metatags');
$twitter = app('seotools.twitter');
$opengraph = app('seotools.opengraph');
$jsonld = app('seotools.json-ld');
$jsonldMulti = app('seotools.json-ld-multi');
// The behavior is the same as the facade
echo app('seotools')->generate();With SEOMeta you can create meta tags to the head
With OpenGraph you can create OpenGraph tags to the head
With Twitter you can create OpenGraph tags to the head
……Pro Tip: Pass the parameter
trueto get minified code and reduce filesize.
<html>
<head>
{!! SEOMeta::generate() !!}
{!! OpenGraph::generate() !!}
{!! Twitter::generate() !!}
{!! JsonLd::generate() !!}
// OR with multi
{!! JsonLdMulti::generate() !!}
{!! SEO::generate() !!}
{!! SEO::generate(true) !!}
{!! app('seotools')->generate() !!}
</head>
<body>
</body>
</html>…Using the same code in multiple places can be tedious, which is why this package includes a Macroable trait. This trait allows additional functionality to be added to a class that was not defined in the class definition, using a simple trait.
For example, imagine that you need to add meta titles and descriptions for your pages. You can add your Macroable functions in the AppServiceProvider or create a dedicated file for this purpose, and define your function as shown in the code snippet:
SEOTools::macro('webPage', function (string $title, string $description) {
SEOMeta::setTitle($title);
SEOMeta::setDescription($description);
SEOMeta::setCanonical('http://current.url.com');
OpenGraph::setDescription($description);
OpenGraph::setTitle($title);
OpenGraph::setUrl('http://current.url.com');
OpenGraph::addProperty('type', 'webpage');
});In your controller, you can use the following code to utilize the function:
SEOTools::webPage('Page title', 'Page description');……………Facilitates access to all the SEO Providers
<?php
use Artesaos\SEOTools\Facades\SEOTools;
SEOTools::metatags();
SEOTools::twitter();
SEOTools::opengraph();
SEOTools::jsonLd();
SEOTools::setTitle($title);
SEOTools::getTitle($session = false);
SEOTools::setDescription($description);
SEOTools::setCanonical($url);
SEOTools::addImages($urls);There are many SEO-related features, which you may need for your project. While this package provides support for the basic ones, other are out of its scope. You'll have to use separate packages for their integration.
This package does not support sitemap files generation. Please consider usage one of the following packages for it:
This package does not handle URL consistency regardless absence or presence of the slash symbol at its end. Please consider usage one of the following packages if you need it:
This package does provide generation of the microdata HTML markup. If you need to create HTML like the following one:
you will need to handle it yourself.
Note: nowadays microdata markup is considered to be outdated. It is recommened to use JSON Linked Data instead, which is supported by this extension.
This package does not support RSS feed generation or related meta data composition. Please consider usage one of the following packages for it:
No open issues yet, or sync has not completed.