Search by

infernalmedia / meta-tags

jlalande

This package provides a component that generates meta tags for your website.

Package info

github.com/infernalmedia/meta-tags

pkg:composer/infernalmedia/meta-tags

Fund package maintenance!

Infernal Média

Statistics

Installs: 1 727

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v2.0.0 2026-12-04 22:32 UTC

This package is auto-updated.

Last update: 2026-12-04 22:32:38 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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_agents rules (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 accepts allow/disallow/null,
  • the shared __usage_ai-training token,
  • 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"> and X-Robots-Tag emit robots.noindex_directives everywhere (the noindex prop can't turn it back on),
  • robots.txt stays permissive — a Disallow would hide the noindex signals and prevent deindexing ("Indexed, though blocked by robots.txt" in Search Console); AI-crawler rules and Sitemap: lines still apply,
  • GET /sitemap.xml serves an empty urlset — the route is only registered in this state, so it shadows the app's real sitemap (a static public/sitemap.xml still wins, as for robots.txt),
  • GET /llms.txt is not registered and <link rel="describedby"> is suppressed — no discovery manifest on a hidden site,
  • ServeGeneratedRobotsTxt intercepts sitemap.xml the 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.