infernalmedia / meta-tags
This package provides a component that generates meta tags for your website.
Fund package maintenance!
Requires
- php: ^8.5
- illuminate/contracts: ^13.0
- spatie/laravel-package-tools: ^1.93
- spatie/schema-org: ^5.0
Requires (Dev)
- larastan/larastan: ^3.15
- laravel/pint: ^1.32
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^11.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-04 22:32:38 UTC
README
A Laravel package that generates everything a page <head> needs: SEO,
Open Graph and Twitter Card meta tags, canonical and hreflang links, site
verifications, a schema.org JSON-LD graph (Organization, WebSite,
BreadcrumbList + your own types), analytics snippets (GTM, Facebook Pixel,
Microsoft Clarity), and — optionally — a generated robots.txt with AI
crawler policies and a llms.txt endpoint.
Requires PHP 8.5+ and Laravel 13+. Upgrading from v1? See MIGRATION.md.
<head> <x-meta-tags :title="$pageTitle ?? null" :description="$pageDescription ?? null" :image="$seoImage ?? null" :breadcrumb="$breadcrumb ?? null" /> </head>
Installation
composer require infernalmedia/meta-tags
php artisan vendor:publish --tag="meta-tags-config"
Optionally publish the views:
php artisan vendor:publish --tag="meta-tags-views"
Usage
Two tags are registered: <x-meta-tags> (alias, disable via
component.alias) and the guaranteed <x-infernal-meta-tags>.
Every prop is nullable — null falls back to config, then to nothing emitted.
| Prop | Type | Effect |
|---|---|---|
title |
?string |
Page title; formatted via title.format (`'{app} |
description |
?string |
meta[name=description] + og:/twitter: descriptions |
image |
string|array |
og:image/twitter:image, merged over image.* config defaults |
type |
?string |
og:type (website, article, …) |
canonical |
string|bool|null |
Canonical link; false disables |
updated-at |
Carbon|string |
og:updated_time |
breadcrumb |
BreadcrumbList|array |
Custom breadcrumb ([['name'=>, 'url'=>]]) |
article |
?array |
article:* properties |
hreflang |
?array |
locale => url map (x-default emitted last) |
noindex |
?bool |
Forces noindex, nofollow |
schemas |
Type|Type[] |
Extra schema.org types added to the JSON-LD graph |
Programmatic access
The MetaTags service (and MetaTags facade) exposes the same logic —
useful in controllers to reuse the Organization/WebSite nodes inside your
own schemas:
use Infernalmedia\MetaTags\MetaTags; use Spatie\SchemaOrg\Schema; Route::get('/blog/{post}', function (MetaTags $meta) { $graph = $meta->graph( Schema::blogPosting()->headline('…')->author($meta->organization()), breadcrumb: [['name' => 'Blog', 'url' => '/blog']], ); return view('post', ['schema' => $graph->toScript()]); });
robots.txt
Set robots_txt.enabled to true to register GET /robots.txt (delete any
static public/robots.txt). The generated file contains:
- your
robots_txt.user_agentsrules (defaults to a permissive*block), - AI crawler policies from
ai.crawlers— default preset blocks training crawlers (GPTBot,ClaudeBot,CCBot,Bytespider,Google-Extended, …) while allowing search/user-triggered agents (OAI-SearchBot,PerplexityBot, …). Every entry acceptsallow/disallow/null, - the shared
__usage_ai-trainingtoken, Sitemap:lines (defaults to{request host}/sitemap.xml— multi-domain safe).
Prefer a middleware (e.g. to intercept other paths too)? Publish ours:
php artisan vendor:publish --tag="meta-tags-middleware" # app/Http/Middleware/ServeGeneratedRobotsTxt.php
llms.txt
Set ai.llms_txt to a file path to serve GET /llms.txt and emit
<link rel="describedby">:
php artisan vendor:publish --tag="meta-tags-llms" # starter llms.txt
AI page-level controls
ai.meta.* emits the vendor-backed controls: Bingbot ai-training /
ai-grounding directives and TDMRep tdm-reservation / tdm-policy.
Stacks
Snippets are pushed to Blade stacks via @pushOnce. stacks.* maps each
feature to a stack your layout defines (null → rendered inline):
'stacks' => [ 'gtm_script' => 'head-js', 'gtm_noscript' => 'top-body', 'facebook_pixel' => 'head-js', 'ms_clarity' => 'head-js', 'json_ld' => 'js', ],
Indexing kill switch
indexing.enabled (INDEXING_ENABLED env) is the indexing kill switch —
off by default, so sites don't index until INDEXING_ENABLED=true is set
in the deployment's .env (opt-in, matching v1's show_website_to_robots
semantics; the legacy SHOW_WEBSITE_TO_ROBOTS env var is honored as a
fallback). It doesn't rely on APP_ENV, so it also protects staging sites
that run APP_ENV=production. While off:
<meta name="robots">andX-Robots-Tagemitrobots.noindex_directiveseverywhere (thenoindexprop can't turn it back on),robots.txtstays permissive — aDisallowwould hide the noindex signals and prevent deindexing ("Indexed, though blocked by robots.txt" in Search Console); AI-crawler rules andSitemap:lines still apply,GET /sitemap.xmlserves an empty urlset — the route is only registered in this state, so it shadows the app's real sitemap (a staticpublic/sitemap.xmlstill wins, as forrobots.txt),GET /llms.txtis not registered and<link rel="describedby">is suppressed — no discovery manifest on a hidden site,ServeGeneratedRobotsTxtinterceptssitemap.xmlthe same way, with no dependence on route order.
Middleware
Infernalmedia\MetaTags\Http\Middleware\EmitRobotsTagHeaders adds
X-Robots-Tag (same directives as the meta tag) to any response — register
it where needed; gated by robots.header.
Extending
Every building block on the service is public or protected — subclass it
and rebind the container to customize any piece (the provider respects an
existing binding, so bind in register() or boot()):
use Infernalmedia\MetaTags\MetaTags; class AppMetaTags extends MetaTags { protected function organizationLogo(): ?ImageObject { return Schema::imageObject()->url(asset('images/logo.png')); } } // AppServiceProvider $this->app->singleton(MetaTags::class, fn () => new AppMetaTags);
The component, facade, controllers and middleware all resolve
MetaTags::class, so the subclass is used everywhere.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.