PHPackages                             straylightagency/metadata - 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. straylightagency/metadata

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

straylightagency/metadata
=========================

An helper package to build metadata tags on PHP pages

03↓100%PHP

Since May 26Pushed 2w agoCompare

[ Source](https://github.com/straylightagency/php-metadata)[ Packagist](https://packagist.org/packages/straylightagency/metadata)[ RSS](/packages/straylightagency-metadata/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Metadata
============

[](#php-metadata)

A helper package to build metadata tags on PHP pages.

Installation
------------

[](#installation)

Require this package with composer.

```
composer require straylightagency/metadata
```

### Laravel without auto-discovery:

[](#laravel-without-auto-discovery)

If you don't use auto-discovery, add the ServiceProvider to the providers array in `config/app.php`:

```
Straylightagency\Metadata\Laravel\MetadataServiceProvider::class,
```

Then add this line to your facades in `config/app.php`:

```
'Metadata' => Straylightagency\Metadata\Laravel\Metadata::class,
```

Usage
-----

[](#usage)

### Without Laravel

[](#without-laravel)

Instantiate a new MetadataManager object and simply use methods provided by.

```
$metadata = new \Straylightagency\Metadata\MetadataManager;

$metadata->title( 'Page Title' );
$metadata->description( 'Website description' );
$metadata->url( 'https://my-website-url.com/my_page/' );
$metadata->author( 'John Doe' );
$metadata->twitterCard( 'app' );
$metadata->twitterImage( asset( '/img/twitter_meta.jpg' ) );
$metadata->ogImage( asset( '/img/facebook_meta.jpg' ), width: 1200, height: 600, type: 'jpeg' );
$metadata->ogType( 'website' );

echo $metadata; // print the meta tags
```

### With Laravel

[](#with-laravel)

The package provides by default a Facade for Laravel application. You can call methods directly using the Facade or use the alias instead.

```
use Straylightagency\Metadata\Laravel\Metadata;

Metadata::title( 'Page title' );
```

### API documentation

[](#api-documentation)

Examples bellow are using Laravel Facade `Metadata`.

#### Set title

[](#set-title)

```
Metadata::title( 'My page title', [flags: int = Metadata::ALL] );
Metadata::metaTitle( 'My page title' ); // only a simple meta title
Metadata::twitterTitle( 'My page title' ); // meta title for Twitter Card
Metadata::ogTitle( 'My page title' ); // meta title for OpenGraph
```

#### Set description

[](#set-description)

```
Metadata::description( 'My page description', [flags: int = Metadata::ALL] );
Metadata::metaDescription( 'My page description' ); // simply a meta description
Metadata::twitterDescription( 'My page description' ); // meta description for Twitter Card
Metadata::ogDescription( 'My page description' ); // meta description for OpenGraph
```

#### Set images

[](#set-images)

You can set many images

```
// Meta image for both Twitter Card and OpenGraph
Metadata::image(
    url: 'https://my-website-url.com/metacard.jpg',
    [secure_url: ?string = null],
    [type: ?string = null],
    [width: ?int = null],
    [height: ?int = null],
    [alt: ?string = null],
    [flags: int = Metadata::ALL]
);

// Twitter Card meta image
Metadata::twitterImage(
    url: 'https://my-website-url.com/metacard.jpg', [alt: ?string = null]
);

// Opengraph meta image
Metadata::ogImage(
    url: 'https://my-website-url.com/metacard.jpg',
    [secure_url: ?string = null],
    [type: ?string = null],
    [width: ?int = null],
    [height: ?int = null],
    [alt: ?string = null]
);
```

#### Set videos for OpenGraph

[](#set-videos-for-opengraph)

```
Metadata::ogVideo(
    url: 'https://my-website-url.com/video.mp4',
    [secure_url: ?string = null],
    [type: ?string = null],
    [width: ?string = null],
    [height: ?string = null]
);
```

#### Set audios for OpenGraph

[](#set-audios-for-opengraph)

```
Metadata::ogAudio(
    url: 'https://my-website-url.com/audio.mp3',
    [secure_url: ?string = null],
    [type: ?string = null]
);
```

#### Set url

[](#set-url)

```
Metadata::url( 'https://my-website-url.com/', [flags: int = Metadata::ALL] ); // meta URL for both Twitter and OpenGraph
Metadata::twitterUrl( 'https://my-website-url.com/' ); // meta URL for Twitter Card
Metadata::ogUrl( 'https://my-website-url.com/' ); // meta URL for OpenGraph
```

#### Set author

[](#set-author)

```
Metadata::author( 'John Doe' );
```

#### Set OpenGraph Type

[](#set-opengraph-type)

```
Metadata::ogType( 'website', [options: array = []]);
```

#### Set Twitter Card Type

[](#set-twitter-card-type)

```
Metadata::twitterCard( 'summary' );
```

#### Set Twitter Site ID

[](#set-twitter-site-id)

```
Metadata::twitterSite( '@my_website_twitter_id' );
```

#### Set Twitter Creator ID

[](#set-twitter-creator-id)

```
Metadata::twitterSite( '@creator_id' );
```

#### Set Facebook App ID

[](#set-facebook-app-id)

```
Metadata::fbAppId( 'facebook_id' );
```

#### Set Facebook Admins ID

[](#set-facebook-admins-id)

```
Metadata::fbAdmins( 'facebook_admins' );
```

#### Set OpenGraph Site Name

[](#set-opengraph-site-name)

```
Metadata::ogSiteName( 'My website name' );
```

#### Set OpenGraph Locale

[](#set-opengraph-locale)

```
Metadata::ogLocale( 'en_US' );
Metadata::ogLocaleAlternate( 'fr_FR', 'nl_BE', 'de_DE' ); // set alternates locales available for this page

// or you can combine both using second parameter of ogLocale :
Metadata::ogLocale( 'en_US', 'fr_FR', 'nl_BE', 'de_DE' );
```

#### Set Google Site Verification ID

[](#set-google-site-verification-id)

```
Metadata::googleSiteVerification( 'google_site_verification_id_from_google_cloud_console' );
```

#### Set Google Bot and Google Bot News

[](#set-google-bot-and-google-bot-news)

```
Metadata::googleBot( 'notranslate' );
Metadata::googleBotNews( 'nosnippet' );
```

#### Set Robots meta

[](#set-robots-meta)

```
Metadata::robots( 'nofollow', 'noindex' );
Metadata::robots( [ 'nofollow', 'noindex' ] ); // works too
```

#### Disable Pinterest Rich Pin

[](#disable-pinterest-rich-pin)

```
Metadata::disablePinterestRichPin([value: bool = true]);
```

#### Set website content rating

[](#set-website-content-rating)

```
Metadata::rating( 'adult' );
```

#### Set a simple meta value

[](#set-a-simple-meta-value)

```
Metadata::meta( 'name', 'some meta value' );
```

#### Set a Twitter Card value

[](#set-a-twitter-card-value)

```
Metadata::twitter( 'name', 'some Twitter Card value', [prefix: MetadataManager::TWITTER_PREFIX], [uniq: bool = false]);
```

#### Set an OpenGraph value

[](#set-an-opengraph-value)

```
Metadata::opengraph( 'name', 'some OpenGraph value', [prefix: MetadataManager::OPENGRAPH_PREFIX], [uniq: bool = false]);

// or use the alias method :
Metadata::og( 'name', 'some OpenGraph value', [prefix: MetadataManager::OPENGRAPH_PREFIX], [uniq: bool = false]);
```

#### Generate the HTML tags

[](#generate-the-html-tags)

```
$html = Metadata::toHtml( [flags: bool = MetadataManager::ALL] );
```

#### Print HTML

[](#print-html)

Simply call the print method will echo the content returned by toHtml() :

```
Metadata::print( [flags: bool = MetadataManager::ALL] );

// or use the __toString magic method :
$metadata = new \Straylightagency\Metadata\MetadataManager;
$metadata->title( 'Page Title' );

echo $metadata; // print the meta title tag
```

### Requirement

[](#requirement)

PHP 8.3 or above

See also
--------

[](#see-also)

- [Google Documentation](https://developers.google.com/search/docs/crawling-indexing/special-tags)
- [Open Graph Documentation](https://ogp.me/)
- [Facebook OG Documentation](https://developers.facebook.com/docs/sharing/webmasters/)
- [Twitter Cards Documentation](https://developer.x.com/en/docs/x-for-websites/cards/guides/getting-started)

Credits
-------

[](#credits)

- [Anthony Pauwels](https://github.com/anthonypauwels)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance63

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4163238?v=4)[Anthony Pauwels](/maintainers/anthonypauwels)[@anthonypauwels](https://github.com/anthonypauwels)

---

Top Contributors

[![anthonypauwels](https://avatars.githubusercontent.com/u/4163238?v=4)](https://github.com/anthonypauwels "anthonypauwels (4 commits)")

### Embed Badge

![Health badge](/badges/straylightagency-metadata/health.svg)

```
[![Health](https://phpackages.com/badges/straylightagency-metadata/health.svg)](https://phpackages.com/packages/straylightagency-metadata)
```

###  Alternatives

[roach-php/core

A complete web scraping toolkit for PHP

1.5k384.0k4](/packages/roach-php-core)

PHPackages © 2026

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