PHPackages                             butschster/meta-tags - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. butschster/meta-tags

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

butschster/meta-tags
====================

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

v3.3.0(2mo ago)628730.7k—2.5%58[4 issues](https://github.com/butschster/LaravelMetaTags/issues)2MITPHPPHP &gt;=8.0CI passing

Since Mar 27Pushed 2mo ago13 watchersCompare

[ Source](https://github.com/butschster/LaravelMetaTags)[ Packagist](https://packagist.org/packages/butschster/meta-tags)[ Fund](https://opencollective.com/laravelmetatags)[ Patreon](https://www.patreon.com/butschster)[ RSS](/packages/butschster-meta-tags/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (51)Used By (2)

[![meta-tags](https://user-images.githubusercontent.com/773481/96843847-730eeb80-1457-11eb-9ee2-806c0650dea6.jpg)](https://user-images.githubusercontent.com/773481/96843847-730eeb80-1457-11eb-9ee2-806c0650dea6.jpg)

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](https://inertiajs.com/), [VueJS](https://nuxtjs.org/docs/2.x/features/meta-tags-seo)and other JavaScript frameworks.**

For any questions or further assistance, please join our official [telegram group](https://t.me/joinchat/bLS_hGWcFxo0MDEy)

Contributing
------------

[](#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!**

[![Support me on Patreon](https://camo.githubusercontent.com/5ab6d2eb5ab9ab057b7d4438491d6e562eb1808058773fba69e5daea884b32ff/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246736869656c6473696f2d70617472656f6e2e76657263656c2e617070253246617069253346757365726e616d652533446275747363687374657225323674797065253344706174726f6e73267374796c653d666c6174)](https://patreon.com/butschster)

[![Build Status](https://camo.githubusercontent.com/a5c1c61b061d97fce77280ab93d1e5a3339bf5a6e9376186e0186c680b4cdeb2/68747470733a2f2f7472617669732d63692e6f72672f627574736368737465722f4c61726176656c4d657461546167732e737667)](https://travis-ci.org/butschster/LaravelMetaTags) [![Latest Stable Version](https://camo.githubusercontent.com/0ff86660bc7140d08efc9d968597286d6246bcf86123f77905c8b237cb76424d/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6d6574612d746167732f762f737461626c65)](https://packagist.org/packages/butschster/meta-tags) [![Total Downloads](https://camo.githubusercontent.com/0cdbd5fa3fd0e26d2c9e6202707601b2cfc8ed4948604126c04f8319a7b17d0b/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6d6574612d746167732f646f776e6c6f616473)](https://packagist.org/packages/butschster/meta-tags) [![License](https://camo.githubusercontent.com/9036b7e7189dd8e8ede535c74da33f8ac1a902af5a6a4ec54dd17d16e5ae0338/68747470733a2f2f706f7365722e707567782e6f72672f627574736368737465722f6d6574612d746167732f6c6963656e7365)](https://packagist.org/packages/butschster/meta-tags)

Supercharge Your Development with Buggregator
---------------------------------------------

[](#supercharge-your-development-with-buggregator)

Pair it with our tool for a more robust development environment. For more information visit [buggregator.dev](https://buggregator.dev)[![](https://private-user-images.githubusercontent.com/773481/285878848-24981ab5-510a-453c-a3c5-8a6f5e7bf358.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NjYzOTMsIm5iZiI6MTc3NDY2NjA5MywicGF0aCI6Ii83NzM0ODEvMjg1ODc4ODQ4LTI0OTgxYWI1LTUxMGEtNDUzYy1hM2M1LThhNmY1ZTdiZjM1OC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzI4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMyOFQwMjQ4MTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNjAzMWY1M2YwOGM2MTNjMDk3NGZlMGU1ODRlMWZmMGY4MGYxOWY1ODZkNzUwYTFmMzg1NTY3Yjg5ODdiNWM0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.jklDo4Jl8AOe0xrqXzwwhmEPt_tJ1BmoOKUkIskScpQ)](https://private-user-images.githubusercontent.com/773481/285878848-24981ab5-510a-453c-a3c5-8a6f5e7bf358.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2NjYzOTMsIm5iZiI6MTc3NDY2NjA5MywicGF0aCI6Ii83NzM0ODEvMjg1ODc4ODQ4LTI0OTgxYWI1LTUxMGEtNDUzYy1hM2M1LThhNmY1ZTdiZjM1OC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzI4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMyOFQwMjQ4MTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNjAzMWY1M2YwOGM2MTNjMDk3NGZlMGU1ODRlMWZmMGY4MGYxOWY1ODZkNzUwYTFmMzg1NTY3Yjg5ODdiNWM0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.jklDo4Jl8AOe0xrqXzwwhmEPt_tJ1BmoOKUkIskScpQ)

Features
--------

[](#features)

- **Meta Management:** Effortlessly set titles, charset, pagination links, and more.
- **Styles &amp; 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 &amp; 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

[](#requirements)

- Laravel version: 9.x to 11.x
- PHP version: 8.0 or higher

Installation and Configuration
------------------------------

[](#installation-and-configuration)

1. **Install the package:** Use the following command to install the Meta Tags package in your awesome application.

```
composer require butschster/meta-tags
```

2. **Register the Service Provider:** After installing the package, you must register its service provider.

You can do it using the following artisan command:

```
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.

3. **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
-----

[](#usage)

### Controller

[](#controller)

You can use either Facade `\Butschster\Head\Facades\Meta` or `\Butschster\Head\Contracts\MetaTags\MetaInterface` in your controller

```
use Butschster\Head\MetaTags\MetaInterface;

class HomeController extends Controller
{
    public function __contruct(
        protected MetaInterface $meta
    ) {
    }

    public function index()
    {
        $news = News::paginate();

        // Prepend title part to the default title
        $this->meta

            // Will render "Home page - Default Title"
           ->prependTitle('Home page')

           // Will include next, prev, canonical links
           ->setPaginationLinks($news)

           // Will change default favicon
           ->setFavicon('/favicon-index.ico')
    }
}

// Or you can use the facade

use Butschster\Head\Facades\Meta;

class HomeController extends Controller
{
    public function index()
    {
        $news = News::paginate();

        Meta::prependTitle('Home page')
            ->setPaginationLinks($news)
            ->setFavicon('favicon-index.ico');
    }
}
```

#### View

[](#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:

```
>

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

...

```

### Placements

[](#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')`

```

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

```

### Packages

[](#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:

```
namespace App\Providers;

use Butschster\Head\Facades\PackageManager;
use Butschster\Head\Packages\Package;
use Illuminate\Support\ServiceProvider;

class MetaTagsServiceProvider extends ServiceProvider
{
    ...
    protected function packages()
    {
       PackageManager::create('jquery', function(Package $package) {
          $package->addScript(
             'jquery.js',
             'https://code.jquery.com/jquery-3.3.1.min.js',
             ['defer']
          );
       });

       PackageManager::create('calendar', function(Package $package) {
          $package->requires('jquery');
          $package->addScript(
             'fullcalendar.js',
             'https://cdn.jsdelivr.net/npm/@fullcalendar/core@4.0.1/main.min.js',
             ['defer']
          )->addScript(
             'fullcalendar.locales.js',
             'https://cdn.jsdelivr.net/npm/@fullcalendar/core@4.0.1/locales-all.min.js',
             ['defer']
          )->addStyle(
             'fullcalendar.css',
             'https://cdn.jsdelivr.net/npm/@fullcalendar/core@4.0.1/main.min.css'
          );
       });
    }

    ...
}
```

#### Using Packages in Controllers

[](#using-packages-in-controllers)

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

```
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

[](#setting-global-packages)

For packages that should be included on every page, you can define them in the `config/meta_tags.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
===

[](#api)

Meta
----

[](#meta)

`\Butschster\Head\MetaTags\Meta`

- This class implements `Illuminate\Contracts\Support\Htmlable` interface

### Methods

[](#methods)

**Set the main part of meta title**

```
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**

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

**Set the title separator**

> By default it gets from config

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

**Set the description**

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

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

**Set the keywords**

```
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**

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

**Set the content type**

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

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

**Set the viewport**

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

**Add webmaster tags** You can add multiple tags

```
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**

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

**Set the next href**

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

**Set the canonical link**

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

**Set canonical link, prev and next from paginator object**

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

Meta::setPaginationLinks($news);

//
//
//
```

**Add a hreflang link**

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

//
//
```

**Set the character encoding for the HTML document**

```
Meta::setCharset();
//

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

**Set the favicon**

```
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**

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

**Add a link to a css file**

```
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**

```
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.

```
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**

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

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

**Get a tag by name**

```
Meta::getTag('author');
```

**Remove a tag by name**

```
Meta::removeTag('author');
```

**Add a meta tag**

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

**Add the CSRF-token tag**

```
Meta::addCsrfToken();
//
```

**Remove all tags**

```
Meta::reset();
```

**Include required packages**

```
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**

```
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

```
$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 package registration
Meta::registerPackage($package);
Meta::replacePackage($newPackage);
```

**Remove package by name**

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

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

**Get package by name**

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

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

$package = Meta::getPackage('custom_package');
```

#### Using meta interfaces

[](#using-meta-interfaces)

A package has different interfaces which help you set meta tags from your objects

**Seo tags**

```
namespace App;
use Butschster\Head\Contracts\MetaTags\SeoMetaTagsInterface;
use Butschster\Head\Contracts\MetaTags\RobotsTagsInterface;

class Page extends Model implements SeoMetaTagsInterface, RobotsTagsInterface {

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function getKeywords()
    {
        return $this->keywords;
    }

    public function getRobots(): ?string
    {
        return 'noindex, nofollow';
    }
}

// Controller
use Butschster\Head\Facades\Meta;

class PageController extends Controller {

    public function show(\App\Page $page)
    {
        Meta::setMetaFrom($page);
    }
}
```

#### Meta extending

[](#meta-extending)

Meta object contains `Macroable` trait and you can extend it!

**For example**

```
//Service Provider
Meta::macro('registerSeoMetaTagsForPage', function (\App\Page $page) {
    $this
        ->prependTitle($page->title)
        ->setKeywords($page->meta_keywords)
        ->setDescription($page->meta_description);

});

// Controller
use Butschster\Head\Facades\Meta;

class PageController extends Controller {

    public function show(\App\Page $page)
    {
        Meta::registerSeoMetaTagsForPage($page);
    }
}
```

> *A little bit infirmation about macroable trait *

### Meta tags placements

[](#meta-tags-placements)

By default, tags place to head placement. You can specify your own placement and use their all available methods.

```
Meta::placement('twitter.meta')
    ->addMeta('twitter:card', [
        'content' => 'summary_large_image',
    ])
    ->includePackages('twitter')

// There is the method for footer placement
Meta::footer()->...

// View

    ...
    @meta_tags('twitter.meta')
    ...

    @meta_tags('footer')

```

Package
-------

[](#package)

A package object has the same methods as Meta object. You can use it for extending and creating custom tags sets.

`\Butschster\Head\Packages\Package`

- This class extend `Butschster\Head\MetaTags\Meta` class
- This class implements `Illuminate\Contracts\Support\Htmlable` interface

**Create a new package and register it in PackageManager**

```
$package = new \Butschster\Head\Packages\Package('jquery');
PackageManager::register($package);

// or
PackageManager::create('jquery', function($package) {
    ...
});
```

**Get the name of the package**

```
$package = new \Butschster\Head\Packages\Package('jquery');

$package->getName(); // jquery
```

**Add a link to a css file**

```
$package = new \Butschster\Head\Packages\Package('jquery');

$package->addStyle('style.css', 'http://site.com/style.css');
//

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

//
```

**Add a link to a script file**

```
$package = new \Butschster\Head\Packages\Package('jquery');

$package->addScript('script.js', 'http://site.com/script.js');
//

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

// You can placement. By default it's footer
$package->addScript('script.js', 'http://site.com/script.js', [], 'custom_placement');
//

Meta::includePackages('jquery')->placement('custom_placement')->toHtml();
```

### Available packages

[](#available-packages)

---

#### OpenGraphPackage

[](#opengraphpackage)

`Butschster\Head\Packages\Entities\OpenGraphPackage`

You can use this package for managing OpenGraph meta tags

```
$og = new Butschster\Head\Packages\Entities\OpenGraphPackage('some_name');

$og->setType('website')
   ->setSiteName('My awesome site')
   ->setTitle('Post title');

// You can render itself

$og->toHtml();
//
//
//

// Or just register this package in Meta class and it will be rendered automatically
Meta::registerPackage($og);
```

**setType** Set the type of your object, e.g., "video.movie".

```
$og->setType('website');
//
```

**setTitle** Set the title of your object as it should appear within the graph, e.g., "The Rock".

```
$og->setTitle('Post title');
//
```

**setDescription** Set the description

```
$og->setDescription('View the album on Flickr.');
//
```

**setSiteName** Set the site name

```
$og->setSiteName('My awesome site');
//
```

**setUrl** Set the canonical URL of your object that will be used as its permanent ID in the graph.

```
$og->setUrl('https://site.com');
//
```

**setLocale** Set the locale these tags are marked up in. Of the format language\_TERRITORY

```
$og->setLocale('en_US');
//
```

**addAlternateLocale**

```
$og->addAlternateLocale('en_US', 'ru_RU');
//
//
```

**addImage** Add an image URL which should represent your object within the graph.

```
$og->addImage('http://site.com');
//

// You can pass properties
$og->addImage('http://site.com', [
    'secure_url' => 'https://site.com',
    'type' => 'image/png'
]);

//
//
//
```

**addVideo** Add an image URL which should represent your object within the graph.

```
$og->addVideo('http://site.com');
//

// You can pass properties
$og->addVideo('http://site.com', [
    'secure_url' => 'https://site.com',
    'type' => 'application/x-shockwave-flash'
]);

//
//
//
```

#### TwitterCardPackage

[](#twittercardpackage)

`Butschster\Head\Packages\Entities\TwitterCardPackage`

You can use this package for managing Twitter card meta tags

```
$card = new Butschster\Head\Packages\Entities\TwitterCardPackage('some_name');

$card->setType('summary')
   ->setSite('@username')
   ->setTitle('Post title');

// You can render itself

$card->toHtml();
//
//
//

// Or just register this package in Meta class and it will be rendered automatically
Meta::registerPackage($card);
```

**setType** Set the type of the card: [summary](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary), [summary\_large\_image](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary-card-with-large-image), [player](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/player-card), [app](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/app-card)

```
$card->setType('summary');
//
```

**setSite** Set the @username for the website used in the card footer.

```
$card->setSite('@username');
//
```

**setCreator** Set the @username for the content creator / author.

```
$card->setCreator('@username');
//
```

**setTitle** Set the title

```
$card->setTitle('Post title');
//
```

**setDescription** Set the description

```
$card->setDescription('View the album on Flickr.');
//
```

**setImage** Set an image for cards that are of type `summary` or `summary_large_image`

```
$card->setImage('https://site.com');
//
```

**setVideo** Set a video to cards that are of type `player`

```
$card->setVideo('https://site.com/video.mp4', ['width' => 1920, 'height' => 1280]);
//
//
//
```

**addMeta** Set a custom meta tag

```
$card->addMeta('image:alt', 'Picture of Pavel Buchnev');
//
```

PackageManager API
------------------

[](#packagemanager-api)

Package manager provide a store for your packages or presets. You can get them by name.

**Create a new package**

```
PackageManager::create('jquery', function($package) {
    ...
});
```

**Register a new package**

```
$package = new \Butschster\Head\Packages\Package('jquery');

PackageManager::register($package);
```

**Get all registered packages**

```
PackageManager::getPackages(): array;
```

**Get registered package by name**

```
PackageManager::create('jquery', function($package) {
    ...
});

PackageManager::getPackage('jquery');
// Will return the registered pacakge or null;
```

### Dependencies

[](#dependencies)

A package can have dependencies.

```
PackageManager::create('jquery', function($package) {
    $package->addScript('jquery.js', 'http://site.com/jquery.min.js');
});

PackageManager::create('bootstrap4', function($package) {
    $package->requires('jquery');
    $package->addScript('bootstrap4.js', 'http://site.com/bootstrap4.min.js');
    $package->addStyle('bootstrap4.css', 'http://site.com/bootstrap4.min.css');
});

Meta::includePackages('bootstrap4');
// Will load jquery package also
// Head
//

// Footer
//
//
```

Helper classes
--------------

[](#helper-classes)

### Tag

[](#tag)

---

`\Butschster\Head\MetaTags\Entities\Tag`

**Create a new tag**

```
$tag = new \Butschster\Head\MetaTags\Entities\Tag('meta', [
    'name' => 'author',
    'content' => 'butschster'
]);
// or
$tag = \Butschster\Head\MetaTags\Entities\Tag::meta([
    'name' => 'author',
    'content' => 'butschster'
]);
$tag->toHtml();
//

// Closed tag
$tag = new \Butschster\Head\MetaTags\Entities\Tag('link', [
    'rel' => 'favicon',
    'href' => 'http://site.com'
], true);
// or
$tag = \Butschster\Head\MetaTags\Entities\Tag::link([
    'rel' => 'favicon',
    'href' => 'http://site.com'
]);

$tag->toHtml();
//

// Tag with anonymous function
$tag = new \Butschster\Head\MetaTags\Entities\Tag('meta', [
    'name' => 'csrf-token',
    'content' => function () {
        return Session::token();
    }
]);

$tag->toHtml();
//
```

**Set the placement**

```
$tag = new \Butschster\Head\MetaTags\Entities\Tag(...);
$tag->setPlacement('footer');
```

**Get the placement**

```
$tag = new \Butschster\Head\MetaTags\Entities\Tag(...);
$tag->getPlacement() // Will return specified placement;
```

**Set visibility condition**

```
$tag = new \Butschster\Head\MetaTags\Entities\Tag(...);
$tag->visibleWhen(function () {
    return Request::ip() === '127.0.0.1';
});
```

### Title

[](#title)

---

`\Butschster\Head\MetaTags\Entities\Title`

This class is responsible for title generation

**Set the default part of the title**

```
$title = new \Butschster\Head\MetaTags\Entities\Title();

$title->setTitle('Laravel');

$title->toHtml(); // Laravel
```

**Prepend a new part of title**

```
$title = new \Butschster\Head\MetaTags\Entities\Title();

$title->setTitle('Laravel');
$title->prepend('Index page');

$title->toHtml(); // Index page | Laravel
```

**Change default title parts separator**

```
$title = new \Butschster\Head\MetaTags\Entities\Title();

$title->setTitle('Laravel');
$title->prepend('Index page');
$title->setSeparator('-');

$title->toHtml(); // Index page - Laravel
```

**Specify max length** *(default length is 255)*

```
$title = new \Butschster\Head\MetaTags\Entities\Title('Lorem Ipsum is simply dummy text of the printing and typesetting');

$title->setMaxLength(20);

$title->toHtml(); // Lorem Ipsum is simpl...
```

### Description

[](#description)

---

`\Butschster\Head\MetaTags\Entities\Description`

#### Script

[](#script)

---

`\Butschster\Head\MetaTags\Entities\Script`

This class is responsible for script links generation

```
use Butschster\Head\MetaTags\Entities\Script;

$script = new Script('jquery.js', 'http://site.com/script.js', ['defer', 'async']);

$script->toHtml();
//

Meta::addTag($script);
```

#### Style

[](#style)

---

`\Butschster\Head\MetaTags\Entities\Style`

This class is responsible for css links generation

```
use Butschster\Head\MetaTags\Entities\Style;

$style = new Style('style.css', 'http://site.com/style.css');

$style->toHtml();
//

Meta::addTag($style);
```

#### Favicon

[](#favicon)

---

`\Butschster\Head\MetaTags\Entities\Favicon`

This class is responsible for favicon link generation

#### Comment

[](#comment)

---

`\Butschster\Head\MetaTags\Entities\Comment`

This class is a wrapper for tags, that allows to add comments to your tags

```
use Butschster\Head\MetaTags\Entities\Comment;
use Butschster\Head\MetaTags\Entities\Favicon;

$favicon = new Favicon('http://site.com/favicon.ico');
$comment = new Comment($favicon, 'Favicon');

Meta::addTag('favicon', $comment);

// Will render

```

#### Conditional comment

[](#conditional-comment)

---

`\Butschster\Head\MetaTags\Entities\ConditionalComment`

This class is a wrapper for tags, that allows to add conditional comments to your tags

```
use Butschster\Head\MetaTags\Entities\ConditionalComment;
use Butschster\Head\MetaTags\Entities\Favicon;

$favicon = new Favicon('http://site.com/favicon.ico');
$comment = new ConditionalComment($favicon, 'IE 6');

Meta::addTag('favicon', $comment);

```

#### Google Analytics

[](#google-analytics)

---

> Has header placement!

```
use Butschster\Head\MetaTags\Entities\GoogleAnalytics;
$script = new GoogleAnalytics('UA-12345678-1');

Meta::addTag('google.analytics', $script);
```

Will return

```

    (function (i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r;
        i[r] = i[r] || function () {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date();
        a = s.createElement(o),
                m = s.getElementsByTagName(o)[0];
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m)
    })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
    ga('create', 'UA-12345678-1', 'auto');
    ga('send', 'pageview');

```

#### Google TagManager

[](#google-tagmanager)

---

> Has header placement!

```
use Butschster\Head\MetaTags\Entities\GoogleTagManager;
$script = new GoogleTagManager('UA-12345678-1');

Meta::addTag('google.tagmanager', $script);
```

Will return

```

    window.dataLayer = window.dataLayer || [];

    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());

    gtag('config', 'UA-12345678-1');

```

#### Yandex Metrika

[](#yandex-metrika)

---

> Has footer placement!

```
use \Butschster\Head\MetaTags\Entities\YandexMetrika;
$script = new YandexMetrika('20925319');

Meta::addTag('yandex.metrika', $script);
```

Will return

```

    (function (m, e, t, r, i, k, a) {
        m[i] = m[i] || function () {
            (m[i].a = m[i].a || []).push(arguments)
        };
        m[i].l = 1 * new Date();
        k = e.createElement(t), a = e.getElementsByTagName(t)[0], k.async = 1, k.src = r, a.parentNode.insertBefore(k, a)
    })
    (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");

    ym(20925319, "init", {clickmap: true, trackLinks: true, accurateTrackBounce: true, webvisor: true});

```

**Change clickmap setting**

```
$script = new YandexMetrika('20925319');

$script->clickmap(bool);
```

**Change webvisor setting**

```
$script = new YandexMetrika('20925319');

$script->webvisor(bool);
```

**Change trackLinks setting**

```
$script = new YandexMetrika('20925319');

$script->trackLinks(bool);
```

**Change accurateTrackBounce setting**

```
$script = new YandexMetrika('20925319');

$script->accurateTrackBounce(bool);
```

**Change trackHash setting**

```
$script = new YandexMetrika('20925319');

$script->trackHash(bool);
```

**Change eCommerce setting**

```
$script = new YandexMetrika('20925319');

$script->eCommerce(string $containerName);
```

**Use alternate CDN**

```
$script = new YandexMetrika('20925319');

$script->useCDN();
```

**Disable noscript tag**

```
$script = new YandexMetrika('20925319');

$script->disableNoScript();
```

#### Javascript variables

[](#javascript-variables)

---

```
use \Butschster\Head\MetaTags\Entities\JavascriptVariables;

$variables = new JavascriptVariables([
    'string' => 'Hello world',
    'number' => 4815162342,
    'bool' => true,
    'nullable' => null
]);

// you can put new variable
$variables->put('array', ['jquery', 'vuejs']);

Meta::addTag('variables', $variables);
```

Will return

```

    window.array = ["jquery", "vuejs"];
    window.string = 'Hello world';
    window.number = 4815162342;
    window.bool = true;
    window.nullable = null;

```

You can change namespace

```
use \Butschster\Head\MetaTags\Entities\JavascriptVariables;

$variables = new JavascriptVariables([
    'string' => 'Hello world',
    'number' => 4815162342,
], 'custom');
```

Will return

```

    window.custom = window.custom || {};
    custom.string = 'Hello world';
    custom.number = 4815162342;

```

Use cases
=========

[](#use-cases)

### Multiple favicons

[](#multiple-favicons)

You can use your own package for that.

At first create your package in the MetaTagsServiceProvider `App\Providers\MetaTagsServiceProvider`

```
namespace App\Providers;

use Butschster\Head\MetaTags\Entities\Favicon;
use Butschster\Head\MetaTags\Entities\ConditionalComment;
use Butschster\Head\Facades\PackageManager;
use Butschster\Head\Packages\Package;

class MetaTagsServiceProvider extends ServiceProvider {

    ...

    protected function packages()
    {
        PackageManager::create('favicons', function(Package $package) {
            $sizes = ['16x16', '32x32', '64x64'];

            foreach ($sizes as $size) {
                $package->addTag(
                    'favicon.'.$size,
                    new Favicon('http://site.com/favicon-'.$size.'.png', [
                        'sizes' => $size
                    ])
                );
            }

            $package->addTag('favicon.ie', new ConditionalComment(
                new Favicon('http://site.com/favicon-ie.png'), 'IE gt 6'
            ));
        });
    }

    ...
}
```

And then append this package into `packages` section in `config/meta_tags.php`:

```
...
'packages' => [
    'favicons'
],
...
```

And the every page you will see in the head seaction something like that:

```

    ...
    ...

    ...

```

Extending
=========

[](#extending)

If you want to extend Meta class you can do it in the `App\Providers\MetaTagsServiceProvider`. Just override `registerMeta` method.

```
namespace App\Providers;

use Butschster\Head\MetaTags\Meta;
use Butschster\Head\Contracts\MetaTags\MetaInterface;
use Butschster\Head\Contracts\Packages\ManagerInterface;

class MetaTagsServiceProvider {

    ...

    protected function registerMeta(): void
    {
        $this->app->singleton(MetaInterface::class, function () {
            $meta = new Meta(
                $this->app[ManagerInterface::class],
                $this->app['config']
            );

            // It just an imagination, you can automatically
            // add favicon if it exists
            if (file_exists(public_path('favicon.ico'))) {
                $meta->setFavicon('/favicon.ico');
            }

            $meta->includePackages('fonts', 'assets');

            // This method gets default values from config and creates tags
            // If you don't want to use default values just remove it.
            $meta->initialize();

            return $meta;
        });
    }

    ...
}
```

Using with inertiajs or vue-meta
================================

[](#using-with-inertiajs-or-vue-meta)

You can easily convert Meta object to array ant the use values in your Js project

```
$meta = Meta::setTitle('Laravel')
    ->setDescription('Awesome page')
    ->setKeywords('php, laravel, ...');

dd($meta->toArray());

[
    'head' => [
        [
            'tag' => 'title',
            'content' => 'Laravel',
        ],
        [
            'name' => 'description',
            'content' => 'Awesome page',
            'type' => 'tag',
            'tag' => 'meta',
        ],
        [
            'name' => 'keywords',
            'content' => 'php, laravel, ...',
            'type' => 'tag',
            'tag' => 'meta',
        ],
    ]
]
```

Example for inertiaJs

```
use Inertia\Inertia;
use Butschster\Head\MetaTags\MetaInterface;
use Butschster\Head\Hydrator\VueMetaHydrator;

class EventsController extends Controller
{
    protected $meta;

    public function __contruct(MetaInterface $meta)
    {
        $this->meta = $meta;
    }

    public function show(Event $event, VueMetaHydrator $hydrator)
    {
        $this->meta->setTitle('Laravel')
            ->setDescription('Awesome page')
            ->setKeywords('php, laravel, ...');

        return Inertia::render('Event/Show', [
            'event' => $event->only('id', 'title', 'start_date', 'description'),

            // this.$page.props.meta...
            'meta' => $hydrator->hydrate($this->meta)
        ]);
    }
}
```

###  Health Score

67

—

FairBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community31

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 80.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~53 days

Recently: every ~100 days

Total

48

Last Release

85d ago

Major Versions

v0.16 → v1.02019-03-30

v1.15 → v2.02021-06-01

2.x-dev → v3.0-beta12023-09-10

PHP version history (2 changes)v0.2-betaPHP &gt;=7.1

v3.0-beta1PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/773481?v=4)[Pavel Buchnev](/maintainers/butschster)[@butschster](https://github.com/butschster)

---

Top Contributors

[![butschster](https://avatars.githubusercontent.com/u/773481?v=4)](https://github.com/butschster "butschster (128 commits)")[![Hladenkyi](https://avatars.githubusercontent.com/u/30920864?v=4)](https://github.com/Hladenkyi "Hladenkyi (6 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (5 commits)")[![atiksoftware](https://avatars.githubusercontent.com/u/14994715?v=4)](https://github.com/atiksoftware "atiksoftware (4 commits)")[![nguyentranchung](https://avatars.githubusercontent.com/u/9611224?v=4)](https://github.com/nguyentranchung "nguyentranchung (3 commits)")[![loranger](https://avatars.githubusercontent.com/u/6014?v=4)](https://github.com/loranger "loranger (3 commits)")[![uintaam](https://avatars.githubusercontent.com/u/295346?v=4)](https://github.com/uintaam "uintaam (2 commits)")[![jadenjoy](https://avatars.githubusercontent.com/u/22222462?v=4)](https://github.com/jadenjoy "jadenjoy (1 commits)")[![joserick](https://avatars.githubusercontent.com/u/15143699?v=4)](https://github.com/joserick "joserick (1 commits)")[![jwcobb](https://avatars.githubusercontent.com/u/777522?v=4)](https://github.com/jwcobb "jwcobb (1 commits)")[![imsus](https://avatars.githubusercontent.com/u/1058471?v=4)](https://github.com/imsus "imsus (1 commits)")[![ihxnnxs](https://avatars.githubusercontent.com/u/62433092?v=4)](https://github.com/ihxnnxs "ihxnnxs (1 commits)")[![mohamedsabil83](https://avatars.githubusercontent.com/u/10126040?v=4)](https://github.com/mohamedsabil83 "mohamedsabil83 (1 commits)")[![henryavila](https://avatars.githubusercontent.com/u/8429941?v=4)](https://github.com/henryavila "henryavila (1 commits)")[![gomzyakov](https://avatars.githubusercontent.com/u/1460709?v=4)](https://github.com/gomzyakov "gomzyakov (1 commits)")

---

Tags

helperlaravelmetameta-tagsmetasopengraphpackagephpseoseo-metaseo-tagslumenlaravel5seometatagsopengraphwebmaster

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/butschster-meta-tags/health.svg)

```
[![Health](https://phpackages.com/badges/butschster-meta-tags/health.svg)](https://phpackages.com/packages/butschster-meta-tags)
```

###  Alternatives

[artesaos/seotools

SEO Tools for Laravel and Lumen

3.3k5.1M60](/packages/artesaos-seotools)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[arcanedev/seo-helper

SEO Helper is a framework agnostic package that provides tools &amp; helpers for SEO (Laravel supported).

332467.0k4](/packages/arcanedev-seo-helper)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[honeystone/laravel-seo

SEO metadata and JSON-LD package for Laravel.

34744.1k](/packages/honeystone-laravel-seo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
