Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

LaravelMetaTags

> 后端框架
Open source

The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project

631 stars0 likes2 views
WebsiteGitHub

About

The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project

The most powerful and extendable tools for managing SEO Meta Tags 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.

For any questions or further assistance, please join our official telegram group

Contributing

We enthusiastically invite you to contribute to the package! Whether you've uncovered a bug, have innovative feature suggestions, or wish to contribute in any other capacity, we warmly welcome your participation. Simply open an issue or submit a pull request on our GitHub repository to get started.

Remember, every great developer was once a beginner. Contributing to open source projects is a step in your journey to becoming a better developer. So, don't hesitate to jump in and start contributing!

We appreciate any contributions to help make the package better!

Supercharge Your Development with Buggregator

Pair it with our tool for a more robust development environment. For more information visit buggregator.dev

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 11.x
  • PHP version: 8.0 or higher

Installation and Configuration

  1. Install the package: Use the following command to install the Meta Tags package in your awesome application.
bash
composer require butschster/meta-tags
  1. Register the Service Provider: After installing the package, you must register its service provider.

You can do it using the following artisan command:

bash
php 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.

  1. Verification: Ensure that App\Providers\MetaTagsServiceProvider has been added to the providers array in your config/app.php configuration file. If it hasn't, you'll need to add it manually. Remember, if your application isn't using the App 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

…

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:

xml

    {!! Meta::toHtml() !!}

...

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')
xml

...
{!! Meta::placement('middle_of_the_page')->toHtml() !!}
...
{!! Meta::footer()->toHtml() !!}

Packages

To avoid code repetition and improve code organization, you can group tags, assets, etc., into named packages. This allows for streamlined inclusion of sets of meta tags or assets where needed.

To create a new package:

  • Navigate to the Service provider.
  • Add your package within \App\Providers\MetaTagsServiceProvider.

To define packages, you can use the PackageManager::create method:

…

Using Packages in Controllers

When specific packages are required within a controller, you can include them by referencing the package name:

php
use Butschster\Head\Facades\Meta;

class EventsController extends Controller {

    public function show(Event $event)
    {
        // Will include all tags from calendar package
        Meta::includePackages(['calendar', ...]);
    }
}

Setting Global Packages

For packages that should be included on every page, you can define them in the config/meta_tags.php:

php
...
'packages' => [
    'jquery', 'calendar', ...
],
...

And there you have it! With these steps, handling and organizing meta tags and assets becomes a breeze.

Note All methods available in the Meta class can also be utilized alongside these package functions.

API

Meta

\Butschster\Head\MetaTags\Meta

  • This class implements Illuminate\Contracts\Support\Htmlable interface

Methods

Set the main part of meta title

php
Meta::setTitle('Laravel');
// Laravel

// You can specify max length. (By default it gets from config.)
Meta::setTitle('Laravel', 4);
// Lara...

Prepend title part to main title

php
Meta::setTitle('Laravel')
    ->prependTitle('Home page');
// Home page - Laravel

Set the title separator

By default it gets from config

php
Meta::setTitleSeparator('->')
    ->setTitle('Laravel')
    ->prependTitle('Home page');
// Home page -> Laravel

Set the description

php
Meta::setDescription('Awesome page');
// 

// You can specify max length. (By default it gets from config.)
Meta::setDescription('Awesome page', 7);
// 

Set the keywords

php
Meta::setKeywords('Awesome keywords');
// 

Meta::setKeywords(['Awesome keyword', 'keyword2']);
// 

// You can specify max length. (By default it gets from config.)
Meta::setKeywords(['keyword', 'keyword2'], 10);
// 

Set the robots

php
Meta::setRobots('nofollow,noindex');
// 

Set the content type

php
Meta::setContentType('text/html');
// 

Meta::setContentType('text/html', 'ISO-8859-1');
// 

Set the viewport

php
Meta::setViewport('width=device-width, initial-scale=1');
// 

Add webmaster tags You can add multiple tags

php
use Butschster\Head\MetaTags\Entities\Webmaster;

// Supported services [google, yandex, pinterest, alexa, bing]
Meta::addWebmaster(Webmaster::GOOGLE, 'f+e-Ww4=[Pp4wyEPLdVx4LxTsQ');
// 

Meta::addWebmaster('yandex', 'f+e-Ww4=[Pp4wyEPLdVx4LxTsQ');
// 

Meta::addWebmaster('bing', 'f+e-Ww4=[Pp4wyEPLdVx4LxTsQ');
// 

Meta::addWebmaster('alexa', 'f+e-Ww4=[Pp4wyEPLdVx4LxTsQ');
// 

Meta::addWebmaster(Webmaster::PINTEREST, 'f+e-Ww4=[Pp4wyEPLdVx4LxTsQ');
// 

Set the prev href

php
Meta::setPrevHref('http://site.com/prev');
// 

Set the next href

php
Meta::setNextHref('http://site.com/next');
// 

Set the canonical link

php
Meta::setCanonical('http://site.com');
// 

Set canonical link, prev and next from paginator object

php
$news = \App\News::paginate();

Meta::setPaginationLinks($news);

// 
// 
// 

Add a hreflang link

php
Meta::setHrefLang('en', http://site.com/en');
Meta::setHrefLang('ru', http://site.com/ru');

// 
// 

Set the character encoding for the HTML document

php
Meta::setCharset();
// 

Meta::setCharset('ISO-8859-1');
// 

Set the favicon

php
Meta::setFavicon('http://site.com/favicon.ico');
// 

Meta::setFavicon('http://site.com/favicon.png');
// 

Meta::setFavicon('http://site.com/favicon.gif');
// 

Meta::setFavicon('http://site.com/favicon.svg');
// 

//You can set additional attributes
Meta::setFavicon('http://site.com/favicon.svg', ['sizes' => '16x16', 'type' => 'custom_type']);
// 

Add a custom link tag

php
Meta::addLink('apple-touch-icon-precomposed', [
    'href' => 'http://site.com',
    'id' => 'id:213'
]);
// 

Add a link to a css file

php
Meta::addStyle('style.css', 'http://site.com/style.css');
// 

// You can override or add attributes
Meta::addStyle('style.css', 'http://site.com/style.css', [
    'media' => 'custom', 'defer', 'async'
]);

// 

Add a link to a script file

php
Meta::addScript('script.js', 'http://site.com/script.js');
// 

// You can override or add attributes
Meta::addScript('script.js', 'http://site.com/script.js', ['async', 'defer', 'id' => 'hj2b3424iu2-dfsfsd']);
// 

// You can specify placement. By default, for scripts it's footer
Meta::addScript('script.js', 'http://site.com/script.js', [], 'custom_placement');
// 

Register a custom tag Our package has a lot of ways of extending. One of them is creating new tags. You are able to create a new class and share it with friends or with the laravel community. You can also create a new pull request if you think that your awesome tag is really useful.

php
class FacebookPixelTag implements \Butschster\Head\Contracts\MetaTags\Entities\TagInterface {

    private $pixel_id;

    public function __construct(string $id)
    {
        $this->pixel_id = $id
    }
   
    public function getPlacement(): string
    {
        return 'footer'
    }

    public function toArray()
    {
        return [
            'type' => 'facebook_pixel_tag',
            'pixel_id' => $this->pixel_id
        ];
    }
    
    public function toHtml()
    {
        return '
'
    }
}

Meta::addTag('facebook.pixel', new FacebookPixelTag('42b3h23-34234'));
// 

Register tags from TagsCollection

php
$tags = new \Butschster\Head\MetaTags\TagsCollection([
    ...
]);
Meta::registerTags($tags);

// You can specify the placement 
Meta::registerTags($tags, 'footer');

Get a tag by name

php
Meta::getTag('author');

Remove a tag by name

php
Meta::removeTag('author');

Add a meta tag

php
Meta::addMeta('author', [
    'content' => 'butschster',
]);
// 

Add the CSRF-token tag

php
Meta::addCsrfToken();
// 

Remove all tags

php
Meta::reset();

Include required packages

php
Meta::includePackages('jquery', 'vuejs');
Meta::includePackages(['jquery', 'vuejs']);

Will load registered packages with names jquery and vuejs and append tags from there to Meta

Register a new package and register all tags from this package

php
Meta::setTitle('Current title');

$package = new \Butschster\Head\Packages\Package('custom_package');
$package->setTitle('New title');

// Will replace "Current title" to "New title" after package registration
Meta::registerPackage($package);

Replace package with the same name When you replace package with a new one, old tags will be removed

php
$package = new \Butschster\Head\Packages\Package('custom_package');
$package->setTitle('Custom title');

$newPackage = new \Butschster\Head\Packages\Package('custom_package');
$newPackage->setTitle('New title');

// Will replace "Current title" to "New title" after

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPhelperlaravelmetameta-tags

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架