Improve Your Laravel Ecommerce Store Technical Seo Using Butschster/laravelmetatags
Last updated on
The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
Technical Seo Configurator For Laravel By Honeystone could be a good alternative for managing Technical SEO in your Laravel project.
Laravel SEO Meta Tags offers a sophisticated solution for Laravel applications, allowing developers to seamlessly manage header meta tags, CSS, JavaScript, and other relevant tags. Its primary objective is to simplify the process of managing search engine optimization (SEO) tags within your application.
Moreover, its versatile API makes it compatible with frameworks like Inertiajs, VueJS and other JavaScript frameworks.
Features
- Meta Management: Effortlessly set titles, charset, pagination links, and more.
- Styles & Scripts: Organize and place styles and scripts anywhere in your HTML.
- Custom Tags: Make your own tags to suit specific needs.
- Rich Media Integration: Supports both Open Graph & Twitter Cards.
- Analytics Ready: Comes with Google Analytics and Yandex Metrika tracking code support, including a code builder for the latter.
- Site Verification: Supports webmaster tools site verifier tags.
- Package System: Group tags, styles, and scripts into named packages for easy inclusion anywhere.
- Robust Documentation: Clear instructions and guidelines for a seamless setup.
- Thoroughly Tested: Built to ensure reliability and stability.
Requirements
- Laravel version: 9.x to 10.x
- PHP version: 8.0 or higher
Installation and Configuration
- Install the package: Use the following command to install the Meta Tags package in your awesome application.
1composer require butschster/meta-tags
- Register the Service Provider: After installing the package, you must register its service provider.
You can do it using the following artisan command:
1php artisan meta-tags:install
This command will activate the App\Providers\MetaTagsServiceProvider
and publish the configuration
at config/meta_tags.php
. Within this configuration file, you can set default titles, keywords, descriptions, and other
meta tags which will be automatically inserted into your HTML.
-
Verification: Ensure that
App\Providers\MetaTagsServiceProvider
has been added to the providers array in yourconfig/app.php
configuration file. If it hasn't, you'll need to add it manually. Remember, if your application isn't using theApp
namespace, update the provider class name accordingly.
And that's all! Your Laravel project is now equipped to handle SEO meta tags with ease.
Usage
Controller
You can use either Facade \Butschster\Head\Facades\Meta
or \Butschster\Head\Contracts\MetaTags\MetaInterface
in your
controller
1use Butschster\Head\MetaTags\MetaInterface; 2 3class HomeController extends Controller 4{ 5 public function __contruct( 6 protected MetaInterface $meta 7 ) { 8 } 9 10 public function index()11 {12 $news = News::paginate();13 14 // Prepend title part to the default title15 $this->meta16 17 // Will render "Home page - Default Title"18 ->prependTitle('Home page')19 20 // Will include next, prev, canonical links21 ->setPaginationLinks($news)22 23 // Will change default favicon24 ->setFavicon('/favicon-index.ico')25 }26}27 28// Or you can use the facade29 30use Butschster\Head\Facades\Meta;31 32class HomeController extends Controller33{34 public function index()35 {36 $news = News::paginate();37 38 Meta::prependTitle('Home page')39 ->setPaginationLinks($news)40 ->setFavicon('favicon-index.ico');41 }42}
View
To integrate meta tags into your HTML, simply insert {!! Meta::toHtml() !!}
wherever required.
Note You have two options to insert meta tags:
{!! Meta::toHtml() !!}
or the Blade directive@meta_tags
.
Here's an example of how you can use it in your view:
1<!DOCTYPE html>2<html lang="en">3<head>4 {!! Meta::toHtml() !!}5</head>6...7</html>
Placements
The package provides flexibility to insert meta tags beyond the header. You can define specific placements in your templates.
- To place meta tags in the footer, use:
Meta::footer()->toHtml()
- For custom placements, use:
Meta::placement('placement_name')->toHtml()
- Alternatively, the Blade directive can also be used:
@meta_tags('placement_name')
1 2<body>3...4{!! Meta::placement('middle_of_the_page')->toHtml() !!}5...6{!! Meta::footer()->toHtml() !!}7</body>
You can learn more about this package, get full installation instructions, and view the source code on GitHub