SEOTools es un paquete para Laravel 5.8+ y Lumen que proporciona ayuda para algunas técnicas de SEO comunes.
Estado de construcción actual
Estadística
Para obtener información sobre la licencia, consulte el archivo LICENCIA.
El primer paso es usar Composer para instalar el paquete y actualizar automáticamente su archivo composer.json
. Puede hacerlo ejecutando:
composer require artesaos/seotools
Nota : si está utilizando Laravel 5.5, los pasos 2 y 3, para proveedores y alias, son innecesarios. SEOTools admite el nuevo descubrimiento de paquetes de Laravel.
Necesita actualizar la configuración de su aplicación para registrar el paquete para que Laravel pueda cargarlo, simplemente actualice su archivo config/app.php
agregando el siguiente código al final de su sección 'providers'
:
config/app.php
<?php
return [
// ...
' providers ' => [
Artesaos SEOTools Providers SEOToolsServiceProvider::class,
// ...
],
// ...
];
Vaya al archivo /bootstrap/app.php
y agregue esta línea:
<?php
// ...
$ app = new Laravel Lumen Application (
dirname ( __DIR__ )
);
// ...
$ app -> register ( Artesaos SEOTools Providers SEOToolsServiceProvider::class);
// ...
return $ app ;
Nota: las fachadas no son compatibles con Lumen.
Puede obtener acceso a los servicios de herramientas de SEO utilizando las siguientes fachadas:
ArtesaosSEOToolsFacadesSEOMeta
ArtesaosSEOToolsFacadesOpenGraph
ArtesaosSEOToolsFacadesTwitterCard
ArtesaosSEOToolsFacadesJsonLd
ArtesaosSEOToolsFacadesJsonLdMulti
ArtesaosSEOToolsFacadesSEOTools
Puede configurar alias de versión corta para estas fachadas en su archivo config/app.php
. Por ejemplo:
<?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,
// ...
],
// ...
];
En tu terminal escribe
php artisan vendor:publish
o
php artisan vendor:publish --provider= " ArtesaosSEOToolsProvidersSEOToolsServiceProvider "
Lumen no soporta este comando, para ello debes copiar el archivo
src/resources/config/seotools.php
alconfig/seotools.php
de tu proyecto
En el archivo de configuración seotools.php
puede determinar las propiedades de los valores predeterminados y algunos comportamientos.
defaults
: qué valores se muestran si no se especifica ningún valor para la visualización de la página. Si el valor es false
, no se muestra nada.webmaster
: son la configuración de los valores de las etiquetas para las principales herramientas para webmasters. Si es null
no se muestra nada.defaults
: son las propiedades que siempre se mostrarán y cuando no se establezca ningún otro valor en su lugar. Puede agregar etiquetas adicionales que no están incluidas en el archivo de configuración original.defaults
: son las propiedades que siempre se mostrarán y cuando no se establezca ningún otro valor en su lugar. Puede agregar etiquetas adicionales que no están incluidas en el archivo de configuración original.defaults
: son las propiedades que siempre se mostrarán y cuando no se establezca ningún otro valor en su lugar. Puede agregar etiquetas adicionales que no están incluidas en el archivo de configuración original. Nota: las fachadas no son compatibles con 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 ();
Con SEOMeta puedes crear metaetiquetas para la head
Con OpenGraph puedes crear etiquetas OpenGraph en la head
Con Twitter puedes crear etiquetas OpenGraph en la head
<?php
namespace App Http Controllers ;
use Artesaos SEOTools Facades SEOMeta ;
use Artesaos SEOTools Facades OpenGraph ;
use Artesaos SEOTools Facades TwitterCard ;
use Artesaos SEOTools Facades JsonLd ;
// OR with multi
use Artesaos SEOTools Facades JsonLdMulti ;
// OR
use Artesaos SEOTools Facades SEOTools ;
class CommonController extends Controller
{
public function index ()
{
SEOMeta:: setTitle ( ' Home ' );
SEOMeta:: setDescription ( ' This is my page description ' );
SEOMeta:: setCanonical ( ' https://codecasts.com.br/lesson ' );
OpenGraph:: setDescription ( ' This is my page description ' );
OpenGraph:: setTitle ( ' Home ' );
OpenGraph:: setUrl ( ' http://current.url.com ' );
OpenGraph:: addProperty ( ' type ' , ' articles ' );
TwitterCard:: setTitle ( ' Homepage ' );
TwitterCard:: setSite ( ' @LuizVinicius73 ' );
JsonLd:: setTitle ( ' Homepage ' );
JsonLd:: setDescription ( ' This is my page description ' );
JsonLd:: addImage ( ' https://codecasts.com.br/img/logo.jpg ' );
// OR
SEOTools:: setTitle ( ' Home ' );
SEOTools:: setDescription ( ' This is my page description ' );
SEOTools:: opengraph ()-> setUrl ( ' http://current.url.com ' );
SEOTools:: setCanonical ( ' https://codecasts.com.br/lesson ' );
SEOTools:: opengraph ()-> addProperty ( ' type ' , ' articles ' );
SEOTools:: twitter ()-> setSite ( ' @LuizVinicius73 ' );
SEOTools:: jsonLd ()-> addImage ( ' https://codecasts.com.br/img/logo.jpg ' );
$ posts = Post:: all ();
return view ( ' myindex ' , compact ( ' posts ' ));
}
public function show ( $ id )
{
$ post = Post:: find ( $ id );
SEOMeta:: setTitle ( $ post -> title );
SEOMeta:: setDescription ( $ post -> resume );
SEOMeta:: addMeta ( ' article:published_time ' , $ post -> published_date -> toW3CString (), ' property ' );
SEOMeta:: addMeta ( ' article:section ' , $ post -> category , ' property ' );
SEOMeta:: addKeyword ([ ' key1 ' , ' key2 ' , ' key3 ' ]);
OpenGraph:: setDescription ( $ post -> resume );
OpenGraph:: setTitle ( $ post -> title );
OpenGraph:: setUrl ( ' http://current.url.com ' );
OpenGraph:: addProperty ( ' type ' , ' article ' );
OpenGraph:: addProperty ( ' locale ' , ' pt-br ' );
OpenGraph:: addProperty ( ' locale:alternate ' , [ ' pt-pt ' , ' en-us ' ]);
OpenGraph:: addImage ( $ post -> cover -> url );
OpenGraph:: addImage ( $ post -> images -> list ( ' url ' ));
OpenGraph:: addImage ([ ' url ' => ' http://image.url.com/cover.jpg ' , ' size ' => 300 ]);
OpenGraph:: addImage ( ' http://image.url.com/cover.jpg ' , [ ' height ' => 300 , ' width ' => 300 ]);
JsonLd:: setTitle ( $ post -> title );
JsonLd:: setDescription ( $ post -> resume );
JsonLd:: setType ( ' Article ' );
JsonLd:: addImage ( $ post -> images -> list ( ' url ' ));
// OR with multi
JsonLdMulti:: setTitle ( $ post -> title );
JsonLdMulti:: setDescription ( $ post -> resume );
JsonLdMulti:: setType ( ' Article ' );
JsonLdMulti:: addImage ( $ post -> images -> list ( ' url ' ));
if (! JsonLdMulti:: isEmpty ()) {
JsonLdMulti:: newJsonLd ();
JsonLdMulti:: setType ( ' WebPage ' );
JsonLdMulti:: setTitle ( ' Page Article - ' . $ post -> title );
}
// Namespace URI: http://ogp.me/ns/article#
// article
OpenGraph:: setTitle ( ' Article ' )
-> setDescription ( ' Some Article ' )
-> setType ( ' article ' )
-> setArticle ([
' published_time ' => ' datetime ' ,
' modified_time ' => ' datetime ' ,
' expiration_time ' => ' datetime ' ,
' author ' => ' profile / array ' ,
' section ' => ' string ' ,
' tag ' => ' string / array '
]);
// Namespace URI: http://ogp.me/ns/book#
// book
OpenGraph:: setTitle ( ' Book ' )
-> setDescription ( ' Some Book ' )
-> setType ( ' book ' )
-> setBook ([
' author ' => ' profile / array ' ,
' isbn ' => ' string ' ,
' release_date ' => ' datetime ' ,
' tag ' => ' string / array '
]);
// Namespace URI: http://ogp.me/ns/profile#
// profile
OpenGraph:: setTitle ( ' Profile ' )
-> setDescription ( ' Some Person ' )
-> setType ( ' profile ' )
-> setProfile ([
' first_name ' => ' string ' ,
' last_name ' => ' string ' ,
' username ' => ' string ' ,
' gender ' => ' enum(male, female) '
]);
// Namespace URI: http://ogp.me/ns/music#
// music.song
OpenGraph:: setType ( ' music.song ' )
-> setMusicSong ([
' duration ' => ' integer ' ,
' album ' => ' array ' ,
' album:disc ' => ' integer ' ,
' album:track ' => ' integer ' ,
' musician ' => ' array '
]);
// music.album
OpenGraph:: setType ( ' music.album ' )
-> setMusicAlbum ([
' song ' => ' music.song ' ,
' song:disc ' => ' integer ' ,
' song:track ' => ' integer ' ,
' musician ' => ' profile ' ,
' release_date ' => ' datetime '
]);
//music.playlist
OpenGraph:: setType ( ' music.playlist ' )
-> setMusicPlaylist ([
' song ' => ' music.song ' ,
' song:disc ' => ' integer ' ,
' song:track ' => ' integer ' ,
' creator ' => ' profile '
]);
// music.radio_station
OpenGraph:: setType ( ' music.radio_station ' )
-> setMusicRadioStation ([
' creator ' => ' profile '
]);
// Namespace URI: http://ogp.me/ns/video#
// video.movie
OpenGraph:: setType ( ' video.movie ' )
-> setVideoMovie ([
' actor ' => ' profile / array ' ,
' actor:role ' => ' string ' ,
' director ' => ' profile /array ' ,
' writer ' => ' profile / array ' ,
' duration ' => ' integer ' ,
' release_date ' => ' datetime ' ,
' tag ' => ' string / array '
]);
// video.episode
OpenGraph:: setType ( ' video.episode ' )
-> setVideoEpisode ([
' actor ' => ' profile / array ' ,
' actor:role ' => ' string ' ,
' director ' => ' profile /array ' ,
' writer ' => ' profile / array ' ,
' duration ' => ' integer ' ,
' release_date ' => ' datetime ' ,
' tag ' => ' string / array ' ,
' series ' => ' video.tv_show '
]);
// video.tv_show
OpenGraph:: setType ( ' video.tv_show ' )
-> setVideoTVShow ([
' actor ' => ' profile / array ' ,
' actor:role ' => ' string ' ,
' director ' => ' profile /array ' ,
' writer ' => ' profile / array ' ,
' duration ' => ' integer ' ,
' release_date ' => ' datetime ' ,
' tag ' => ' string / array '
]);
// video.other
OpenGraph:: setType ( ' video.other ' )
-> setVideoOther ([
' actor ' => ' profile / array ' ,
' actor:role ' => ' string ' ,
' director ' => ' profile /array ' ,
' writer ' => ' profile / array ' ,
' duration ' => ' integer ' ,
' release_date ' => ' datetime ' ,
' tag ' => ' string / array '
]);
// og:video
OpenGraph:: addVideo ( ' http://example.com/movie.swf ' , [
' secure_url ' => ' https://example.com/movie.swf ' ,
' type ' => ' application/x-shockwave-flash ' ,
' width ' => 400 ,
' height ' => 300
]);
// og:audio
OpenGraph:: addAudio ( ' http://example.com/sound.mp3 ' , [
' secure_url ' => ' https://secure.example.com/sound.mp3 ' ,
' type ' => ' audio/mpeg '
]);
// og:place
OpenGraph:: setTitle ( ' Place ' )
-> setDescription ( ' Some Place ' )
-> setType ( ' place ' )
-> setPlace ([
' location:latitude ' => ' float ' ,
' location:longitude ' => ' float ' ,
]);
return view ( ' myshow ' , compact ( ' post ' ));
}
}
<?php
namespace App Http Controllers ;
use Artesaos SEOTools Traits SEOTools as SEOToolsTrait ;
class CommonController extends Controller
{
use SEOToolsTrait;
public function index ()
{
$ this -> seo ()-> setTitle ( ' Home ' );
$ this -> seo ()-> setDescription ( ' This is my page description ' );
$ this -> seo ()-> opengraph ()-> setUrl ( ' http://current.url.com ' );
$ this -> seo ()-> opengraph ()-> addProperty ( ' type ' , ' articles ' );
$ this -> seo ()-> twitter ()-> setSite ( ' @LuizVinicius73 ' );
$ this -> seo ()-> jsonLd ()-> setType ( ' Article ' );
$ posts = Post:: all ();
return view ( ' myindex ' , compact ( ' posts ' ));
}
}
Consejo profesional : pase el parámetro
true
para obtener código minimizado y reducir el tamaño del archivo.
< html >
< head >
{!! SEOMeta::generate() !!}
{!! OpenGraph::generate() !!}
{!! Twitter::generate() !!}
{!! JsonLd::generate() !!}
// OR with multi
{!! JsonLdMulti::generate() !!}
<!-- OR -->
{!! SEO::generate() !!}
<!-- MINIFIED -->
{!! SEO::generate(true) !!}
<!-- LUMEN -->
{!! app('seotools')- > generate() !!}
</ head >
< body >
</ body >
</ html >
< html >
< head >
< title > Title - Over 9000 Thousand! </ title >
< meta name =' description ' itemprop =' description ' content =' description... ' >
< meta name =' keywords ' content =' key1, key2, key3 ' >
< meta property =' article:published_time ' content =' 2015-01-31T20:30:11-02:00 ' >
< meta property =' article:section ' content =' news ' >
< meta property =" og:description " content =" description... " >
< meta property =" og:title " content =" Title " >
< meta property =" og:url " content =" http://current.url.com " >
< meta property =" og:type " content =" article " >
< meta property =" og:locale " content =" pt-br " >
< meta property =" og:locale:alternate " content =" pt-pt " >
< meta property =" og:locale:alternate " content =" en-us " >
< meta property =" og:site_name " content =" name " >
< meta property =" og:image " content =" http://image.url.com/cover.jpg " >
< meta property =" og:image " content =" http://image.url.com/img1.jpg " >
< meta property =" og:image " content =" http://image.url.com/img2.jpg " >
< meta property =" og:image " content =" http://image.url.com/img3.jpg " >
< meta property =" og:image:url " content =" http://image.url.com/cover.jpg " >
< meta property =" og:image:size " content =" 300 " >
< meta name =" twitter:card " content =" summary " >
< meta name =" twitter:title " content =" Title " >
< meta name =" twitter:site " content =" @LuizVinicius73 " >
< script type =" application/ld+json " > { "@context" : "https://schema.org" , "@type" : "Article" , "name" : "Title - Over 9000 Thousand!" } </ script >
<!-- OR with multi -->
< script type =" application/ld+json " > { "@context" : "https://schema.org" , "@type" : "Article" , "name" : "Title - Over 9000 Thousand!" } </ script >
< script type =" application/ld+json " > { "@context" : "https://schema.org" , "@type" : "WebPage" , "name" : "Title - Over 9000 Thousand!" } </ script >
</ head >
< body >
</ body >
</ html >
Usar el mismo código en varios lugares puede resultar tedioso, por lo que este paquete incluye una característica Macroable. Este rasgo permite agregar funcionalidad adicional a una clase que no estaba definida en la definición de clase, utilizando un rasgo simple.
Por ejemplo, imagine que necesita agregar metatítulos y descripciones para sus páginas. Puede agregar sus funciones Macroable en AppServiceProvider o crear un archivo dedicado para este propósito y definir su función como se muestra en el fragmento de código:
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 ' );
});
En su controlador, puede usar el siguiente código para utilizar la función:
SEOTools:: webPage ( ' Page title ' , ' Page description ' );
<?php
use Artesaos SEOTools Facades SEOMeta ;
SEOMeta:: addKeyword ( $ keyword );
SEOMeta:: addMeta ( $ meta , $ value = null , $ name = ' name ' );
SEOMeta:: addAlternateLanguage ( $ lang , $ url );
SEOMeta:: addAlternateLanguages (array $ languages );
SEOMeta:: setAlternateLanguage ( $ lang , $ url );
SEOMeta:: setAlternateLanguages (array $ languages );
SEOMeta:: setTitleSeparator ( $ separator );
SEOMeta:: setTitle ( $ title );
SEOMeta:: setTitleDefault ( $ default );
SEOMeta:: setDescription ( $ description );
SEOMeta:: setKeywords ( $ keywords );
SEOMeta:: setRobots ( $ robots );
SEOMeta:: setCanonical ( $ url );
SEOMeta:: setPrev ( $ url );
SEOMeta:: setNext ( $ url );
SEOMeta:: removeMeta ( $ key );
// You can chain methods
SEOMeta:: setTitle ( $ title )
-> setDescription ( $ description )
-> setKeywords ( $ keywords )
-> addKeyword ( $ keyword )
-> addMeta ( $ meta , $ value );
// Retrieving data
SEOMeta:: getTitle ();
SEOMeta:: getTitleSession ();
SEOMeta:: getTitleSeparator ();
SEOMeta:: getKeywords ();
SEOMeta:: getDescription ();
SEOMeta:: getCanonical ( $ url );
SEOMeta:: getPrev ( $ url );
SEOMeta:: getNext ( $ url );
SEOMeta:: getRobots ();
SEOMeta:: reset ();
SEOMeta:: generate ();
<?php
use Artesaos SEOTools Facades OpenGraph ;
OpenGraph:: addProperty ( $ key , $ value ); // value can be string or array
OpenGraph:: addImage ( $ url ); // add image url
OpenGraph:: addImages ( $ url ); // add an array of url images
OpenGraph:: setTitle ( $ title ); // define title
OpenGraph:: setDescription ( $ description ); // define description
OpenGraph:: setUrl ( $ url ); // define url
OpenGraph:: setSiteName ( $ name ); //define site_name
// You can chain methods
OpenGraph:: addProperty ( $ key , $ value )
-> addImage ( $ url )
-> addImages ( $ url )
-> setTitle ( $ title )
-> setDescription ( $ description )
-> setUrl ( $ url )
-> setSiteName ( $ name );
// Generate html tags
OpenGraph:: generate ();
<?php
use Artesaos SEOTools Facades TwitterCard ;
TwitterCard:: addValue ( $ key , $ value ); // value can be string or array
TwitterCard:: setType ( $ type ); // type of twitter card tag
TwitterCard:: setTitle ( $ type ); // title of twitter card tag
TwitterCard:: setSite ( $ type ); // site of twitter card tag
TwitterCard:: setDescription ( $ type ); // description of twitter card tag
TwitterCard:: setUrl ( $ type ); // url of twitter card tag
TwitterCard:: setImage ( $ url ); // add image url
// You can chain methods
TwitterCard:: addValue ( $ key , $ value )
-> setType ( $ type )
-> setImage ( $ url )
-> setTitle ( $ title )
-> setDescription ( $ description )
-> setUrl ( $ url )
-> setSite ( $ name );
// Generate html tags
TwitterCard:: generate ();
<?php
use Artesaos SEOTools Facades JsonLd ;
JsonLd:: addValue ( $ key , $ value ); // value can be string or array
JsonLd:: setType ( $ type ); // type of twitter card tag
JsonLd:: setTitle ( $ type ); // title of twitter card tag
JsonLd:: setSite ( $ type ); // site of twitter card tag
JsonLd:: setDescription ( $ type ); // description of twitter card tag
JsonLd:: setUrl ( $ type ); // url of twitter card tag
JsonLd:: setImage ( $ url ); // add image url
// You can chain methods
JsonLd:: addValue ( $ key , $ value )
-> setType ( $ type )
-> setImage ( $ url )
-> setTitle ( $ title )
-> setDescription ( $ description )
-> setUrl ( $ url )
-> setSite ( $ name );
// Generate html tags
JsonLd:: generate ();
<?php
use Artesaos SEOTools Facades JsonLdMulti ;
JsonLdMulti:: newJsonLd (); // create a new JsonLd group
JsonLdMulti:: isEmpty (); // check if the current JsonLd group is empty
JsonLdMulti:: select ( $ index ); // choose the JsonLd group that will be edited by the methods below
JsonLdMulti:: addValue ( $ key , $ value ); // value can be string or array
JsonLdMulti:: setType ( $ type ); // type of twitter card tag
JsonLdMulti:: setTitle ( $ type ); // title of twitter card tag
JsonLdMulti:: setSite ( $ type ); // site of twitter card tag
JsonLdMulti:: setDescription ( $ type ); // description of twitter card tag
JsonLdMulti:: setUrl ( $ type ); // url of twitter card tag
JsonLdMulti:: setImage ( $ url ); // add image url
// You can chain methods
JsonLdMulti:: addValue ( $ key , $ value )
-> setType ( $ type )
-> setImage ( $ url )
-> setTitle ( $ title )
-> setDescription ( $ description )
-> setUrl ( $ url )
-> setSite ( $ name );
// You can add an other group
if (! JsonLdMulti:: isEmpty ()) {
JsonLdMulti:: newJsonLd ()
-> setType ( $ type )
-> setImage ( $ url )
-> setTitle ( $ title )
-> setDescription ( $ description )
-> setUrl ( $ url )
-> setSite ( $ name );
}
// Generate html tags
JsonLdMulti:: generate ();
// You will have retrieve <script content="application/ld+json"/>
Facilita el acceso a todos los Proveedores SEO
<?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 );
Hay muchas funciones relacionadas con SEO que puede necesitar para su proyecto. Si bien este paquete brinda soporte para los básicos, otros están fuera de su alcance. Tendrás que utilizar paquetes separados para su integración.
Este paquete no admite la generación de archivos de mapas del sitio. Considere utilizar uno de los siguientes paquetes para ello:
laravelio/mapa del sitio
spatie/laravel-mapa del sitio
Este paquete no maneja la coherencia de la URL independientemente de la ausencia o presencia del símbolo de barra diagonal al final. Considere utilizar uno de los siguientes paquetes si lo necesita:
Illuminach/url-barra-posterior
fsasvari/laravel-barra-final
Este paquete proporciona la generación del marcado HTML de microdatos. Si necesita crear HTML como el siguiente:
< div itemscope >
< p > My name is
< span itemprop =" name " > Elizabeth </ span > . </ p >
</ div >
tendrás que encargarte tú mismo.
Nota: hoy en día el marcado de microdatos se considera obsoleto. Se recomienda utilizar JSON Linked Data en su lugar, que es compatible con esta extensión.
Este paquete no admite la generación de fuentes RSS ni la composición de metadatos relacionados. Considere utilizar uno de los siguientes paquetes para ello: