PHPackages                             chriskonnertz/open-graph - 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. chriskonnertz/open-graph

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

chriskonnertz/open-graph
========================

Class that assists in building Open Graph meta tags

v2.0.0(6y ago)117428.6k↓32.8%15[2 issues](https://github.com/chriskonnertz/open-graph/issues)[1 PRs](https://github.com/chriskonnertz/open-graph/pulls)3MITPHPPHP &gt;=7.0

Since Dec 11Pushed 5y ago3 watchersCompare

[ Source](https://github.com/chriskonnertz/open-graph)[ Packagist](https://packagist.org/packages/chriskonnertz/open-graph)[ RSS](/packages/chriskonnertz-open-graph/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (12)Used By (3)

Open Graph Builder
==================

[](#open-graph-builder)

[![Build Status](https://camo.githubusercontent.com/e585131f80b6e602abe15c7883b1b912e6f420ed13d40a95eff36573d1be2b4e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63687269736b6f6e6e6572747a2f6f70656e2d67726170682e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/chriskonnertz/open-graph)[![Monthly Downloads](https://camo.githubusercontent.com/4ed1798da6368717b125099821977fabe5ca0e958d0aec52aa00ca02f8aee8d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f63687269736b6f6e6e6572747a2f6f70656e2d67726170682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chriskonnertz/open-graph)[![Version](https://camo.githubusercontent.com/7df7d8961efd9d4da05b1e1cf185bd29422eb0309ba6fbdd847f2d69fcfe8120/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63687269736b6f6e6e6572747a2f6f70656e2d67726170682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chriskonnertz/open-graph)[![GitHub license](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://raw.githubusercontent.com/chriskonnertz/open-graph/master/LICENSE)

Library that assists in building Open Graph meta tags.

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

[](#installation)

Add `chriskonnertz/open-graph` to `composer.json` with a text editor:

```
"chriskonnertz/open-graph": "~2"

```

Or via a console:

```
composer require chriskonnertz/open-graph

```

In the future use `composer update` to update to the latest version of Open Graph Builder.

> This library requires PHP &gt;=7.0.

### Framework Support

[](#framework-support)

Laravel &gt;=5.5 can auto-detect this package so you can ignore this section. In Laravel 5.0-5.4 you have to edit your `config/app.php` config file. You can either add an alias to the object so you can create a new instance via `new OpenGraph()` ...

```
'aliases' => [
    ...
    'OpenGraph' => 'ChrisKonnertz\OpenGraph\OpenGraph',
],
```

...or an alias to the facade (this is what happens in Laravel &gt;=5.5 via package auto-discovery) so you do not have to create the instance by yourself but you can access it via pseudo-static methods. If you choose this path you also have to add the service provider to the config file:

```
'aliases' => [
    ...
    'OpenGraph' => 'ChrisKonnertz\OpenGraph\OpenGraphFacade',
],

...

'providers' => [
    ...
    'ChrisKonnertz\OpenGraph\OpenGraphServiceProvider',
],
```

> If you need to reset the underlying instance of the facade (the `OpenGraph` object), call `OpenGraph::clear()`.

Introduction
------------

[](#introduction)

Example:

```
$og = OpenGraph::title('Apple Cookie')
    ->type('article')
    ->image('http://example.org/apple.jpg')
    ->description('Welcome to the best apple cookie recipe never created.')
    ->url();
```

Render these tags in a template as follows:

```
{!! $og->renderTags() !!}

```

Providing Open Graph tags enriches web pages. The downside is some extra time to spend, because every model has its own way to generate these tags. It's also important to follow the [official protocol](http://ogp.me/). Read the documentation to learn more about the tags that are available and the values they support or [check out examples](https://github.com/niallkennedy/open-graph-protocol-examples). Please note that this implementation sticks to the specification of OGP.me and does not support the enhancements created by Facebook.

Add Tags And Attributes
-----------------------

[](#add-tags-and-attributes)

### Add Basic Tags

[](#add-basic-tags)

```
$og->title('Apple Cookie')
    ->type('article')
    ->description('A delicious recipe')
    ->url()
    ->locale('en_US')
    ->localeAlternate(['en_UK'])
    ->siteName('Cookie Recipes Website')
    ->determiner('an');
```

> If no argument is passed to the `url` method the current URL is applied. Note that the environment variable `APP_URL` is considered if it is set. Furthermore, when executed via CLI, and `APP_URL` is not set, the domain will be `localhost`.

Note that `DateTime` objects will be converted to [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) strings.

### Add Tags With Attributes

[](#add-tags-with-attributes)

You may add `image`, `audio` or `video` tags and pass the basic value (the URL to the object) and an array of additional attributes.

```
$og->image($imageUrl, [
    'width'     => 300,
    'height'    => 200
]);

$og->audio($audioUrl, [
    'type'     => 'audio/mpeg'
]);

$og->video($videoUrl, [
    'width'     => 300,
    'height'    => 200,
    'type'      => 'application/x-shockwave-flash'
]);
```

### Add Type Attributes

[](#add-type-attributes)

Some object types (determined by the `type` tag) have their own tags with attributes but not a basic tag. These are `article`, `book` and `profile`.

```
$og->article([
    'author'        => 'Jane Doe'
]);

$og->book([
    'author'        => 'John Doe'
]);

$og->profile([
    'first_name'    => 'Kim',
    'last_name'     => 'Doe'
]);
```

### Add Attributes

[](#add-attributes)

Facebook supports more than just the basic object types. To add attributes for off-the-record object types you may use the `attributes` method.

Without custom validation rule:

```
$og->attributes('product', ['product:color' => 'red']);
```

With custom validation rule:

```
$og->attributes('product', ['product:color' => 'red'], ['product:color']);
```

The only validation this method performs is to check if all attribute names match with the list of attribute names.

### Add A Tag Several Times

[](#add-a-tag-several-times)

A property can have multiple values. Add the tag several times to achieve this effect.

```
$og->image('http://example.org/apple.jpg')
    ->image('http://example.org/tree.jpg');
```

> Adding a basic tag a second time will override the value of the first tag. Basic tags must not exist several times.

Validation
----------

[](#validation)

If validation is enabled (default is disabled) adding tags will trigger validation. Validation is not covering the complete specification but some important parts. If validation fails the method will throw an exception.

Validation checks if tag values are legit and if attribute types are known.

Enable validation by method:

```
$og->validate();
```

By constructor:

```
$og = new OpenGraph(true);
```

Disable validation:

```
$og->validate(false);
```

Miscellaneous
-------------

[](#miscellaneous)

### Determine If A Tag Exists

[](#determine-if-a-tag-exists)

```
$hasTitle = $og->has('title');
```

### Remove A Tag From The List

[](#remove-a-tag-from-the-list)

```
$og->forget('title');
```

### Remove All Tags From The List

[](#remove-all-tags-from-the-list)

```
$og->clear();
```

### Add A Custom Tag

[](#add-a-custom-tag)

```
$og->tag('apples', 7);
```

> To disable auto-prefixing pass a third parameter: `$og->tag('apples', 7, false)`

### Get The Last Tag (By Name)

[](#get-the-last-tag-by-name)

```
$tag = $og->lastTag('image');
$value = $tag['value'];
```

> Tags are stored as arrays consisting of name-value-pairs.

Status
------

[](#status)

Status of this repository: **Maintained**. If you create an issue you will get a response usually within 48 hours.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% 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 ~128 days

Recently: every ~42 days

Total

11

Last Release

2525d ago

Major Versions

v1.0.7 → v2.0.0-beta2019-04-18

PHP version history (2 changes)v1.0.0PHP &gt;=5.3.7

v2.0.0-betaPHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2548d359f2033681fd886f21a31406119a9ea3bd93dbec6f533f75f006f09228?d=identicon)[siconize](/maintainers/siconize)

---

Top Contributors

[![chriskonnertz](https://avatars.githubusercontent.com/u/4319323?v=4)](https://github.com/chriskonnertz "chriskonnertz (173 commits)")[![FabrizioCafolla](https://avatars.githubusercontent.com/u/13237032?v=4)](https://github.com/FabrizioCafolla "FabrizioCafolla (1 commits)")[![KalanaPerera](https://avatars.githubusercontent.com/u/13487065?v=4)](https://github.com/KalanaPerera "KalanaPerera (1 commits)")[![samwalshnz](https://avatars.githubusercontent.com/u/1085227?v=4)](https://github.com/samwalshnz "samwalshnz (1 commits)")[![wast](https://avatars.githubusercontent.com/u/9076227?v=4)](https://github.com/wast "wast (1 commits)")

---

Tags

graphlaravelmetatagsogpopenopen-graphopengraphphpseotagslaravellaravel5opengraphopen-graphogp

### Embed Badge

![Health badge](/badges/chriskonnertz-open-graph/health.svg)

```
[![Health](https://phpackages.com/badges/chriskonnertz-open-graph/health.svg)](https://phpackages.com/packages/chriskonnertz-open-graph)
```

###  Alternatives

[artesaos/seotools

SEO Tools for Laravel and Lumen

3.3k5.1M60](/packages/artesaos-seotools)[butschster/meta-tags

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

628730.7k2](/packages/butschster-meta-tags)[brexis/laravel-workflow

Integerate Symfony Workflow component into Laravel.

283125.6k](/packages/brexis-laravel-workflow)[summerblue/generator

Extend Laravel's generators scaffold.

34139.9k](/packages/summerblue-generator)[jonom/silverstripe-share-care

Social media sharing previews and customisation for Silverstripe

2932.7k1](/packages/jonom-silverstripe-share-care)[umanskyi31/opengraph

Created a new component for Yii2. The Open Graph component for your website

119.7k](/packages/umanskyi31-opengraph)

PHPackages © 2026

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