Работа с метатегами — SEO Tools для Laravel
Пакет для работы с SEO.
Вставка метатегов title, description и т.д.
Метатеги Twitter Cards and Open Graph.
Пример использования:
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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 CommomController 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')); } } |
Во View:
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<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> |
API (SEOMeta):
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
use Artesaos\SEOTools\Facades\SEOMeta; SEOMeta::addKeyword($keyword); SEOMeta::addMeta($meta, $value = null, $name = 'name'); SEOMeta::addAlternateLanguage($lang, $url); SEOMeta::addAlternateLanguages(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(); |
https://github.com/artesaos/seotools
Recommended Posts
Не работает autocomplete в моделях Laravel
01.02.2022