{"id":13318748,"url":"https://github.com/chriskonnertz/open-graph","last_synced_at":"2025-04-06T01:08:16.336Z","repository":{"id":15329160,"uuid":"18059416","full_name":"chriskonnertz/open-graph","owner":"chriskonnertz","description":"Library that assists in building Open Graph meta tags","archived":false,"fork":false,"pushed_at":"2021-03-16T22:13:48.000Z","size":189,"stargazers_count":116,"open_issues_count":7,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-15T20:35:22.480Z","etag":null,"topics":["graph","laravel","metatags","ogp","open","open-graph","opengraph","php","seo","tags"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chriskonnertz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-24T10:50:33.000Z","updated_at":"2024-05-03T10:26:41.000Z","dependencies_parsed_at":"2022-08-30T12:11:16.913Z","dependency_job_id":null,"html_url":"https://github.com/chriskonnertz/open-graph","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2Fopen-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2Fopen-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2Fopen-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2Fopen-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chriskonnertz","download_url":"https://codeload.github.com/chriskonnertz/open-graph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276070,"owners_count":20912287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph","laravel","metatags","ogp","open","open-graph","opengraph","php","seo","tags"],"created_at":"2024-07-29T18:30:52.981Z","updated_at":"2025-04-06T01:08:16.318Z","avatar_url":"https://github.com/chriskonnertz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Open Graph Builder\n\n[![Build Status](https://img.shields.io/travis/chriskonnertz/open-graph.svg?style=flat-square)](https://travis-ci.org/chriskonnertz/open-graph)\n[![Monthly Downloads](https://img.shields.io/packagist/dm/chriskonnertz/open-graph.svg?style=flat-square)](https://packagist.org/packages/chriskonnertz/open-graph)\n[![Version](https://img.shields.io/packagist/v/chriskonnertz/open-graph.svg?style=flat-square)](https://packagist.org/packages/chriskonnertz/open-graph)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/chriskonnertz/open-graph/master/LICENSE)\n\nLibrary that assists in building Open Graph meta tags.\n\n## Installation\n\nAdd `chriskonnertz/open-graph` to `composer.json` with a text editor:\n\n```\n\"chriskonnertz/open-graph\": \"~2\"\n```\n    \nOr via a console:\n\n```\ncomposer require chriskonnertz/open-graph\n```\n\nIn the future use `composer update` to update to the latest version of Open Graph Builder.\n\n\u003e This library requires PHP \u003e=7.0.\n\n### Framework Support\n\nLaravel \u003e=5.5 can auto-detect this package so you can ignore this section. \nIn Laravel 5.0-5.4 you have to edit your `config/app.php` config file. \nYou can either add an alias to the object so you can create a new instance via `new OpenGraph()` ...\n\n```php\n'aliases' =\u003e [\n    ...\n    'OpenGraph' =\u003e 'ChrisKonnertz\\OpenGraph\\OpenGraph',\n],\n```\n\n...or an alias to the facade (this is what happens in Laravel \u003e=5.5 via package auto-discovery) so you\ndo not have to create the instance by yourself but you can access it via pseudo-static methods. \nIf you choose this path you also have to add the service provider to the config file:\n\n```php\n'aliases' =\u003e [\n    ...\n    'OpenGraph' =\u003e 'ChrisKonnertz\\OpenGraph\\OpenGraphFacade',\n],\n\n...\n\n'providers' =\u003e [\n    ...\n    'ChrisKonnertz\\OpenGraph\\OpenGraphServiceProvider',\n],\n```\n\n\u003e If you need to reset the underlying instance of the facade (the `OpenGraph` object), call `OpenGraph::clear()`.\n\n## Introduction\n\nExample:\n\n```php\n$og = OpenGraph::title('Apple Cookie')\n    -\u003etype('article')\n    -\u003eimage('http://example.org/apple.jpg')\n    -\u003edescription('Welcome to the best apple cookie recipe never created.')\n    -\u003eurl();\n```\n\nRender these tags in a template as follows:\n\n```\n{!! $og-\u003erenderTags() !!}\n```\n\nProviding 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.\n\n## Add Tags And Attributes\n\n### Add Basic Tags\n\n```php\n$og-\u003etitle('Apple Cookie')\n    -\u003etype('article')\n    -\u003edescription('A delicious recipe')\n    -\u003eurl()\n    -\u003elocale('en_US')\n    -\u003elocaleAlternate(['en_UK'])\n    -\u003esiteName('Cookie Recipes Website')\n    -\u003edeterminer('an');\n```\n\n\u003e 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`.\n\nNote that `DateTime` objects will be converted to [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) strings.\n\n### Add Tags With Attributes\n\nYou may add `image`, `audio` or `video` tags and pass the basic value (the URL to the object) and an array of additional attributes.\n\n```php\n$og-\u003eimage($imageUrl, [\n    'width'     =\u003e 300,\n    'height'    =\u003e 200\n]);\n\n$og-\u003eaudio($audioUrl, [\n    'type'     =\u003e 'audio/mpeg'\n]);\n\n$og-\u003evideo($videoUrl, [\n    'width'     =\u003e 300,\n    'height'    =\u003e 200,\n    'type'      =\u003e 'application/x-shockwave-flash'\n]);\n```\n\n### Add Type Attributes\n\nSome object types (determined by the `type` tag) have their own tags with attributes but not a basic tag. These are `article`, `book` and `profile`.\n\n```php\n$og-\u003earticle([\n    'author'        =\u003e 'Jane Doe'\n]);\n\n$og-\u003ebook([\n    'author'        =\u003e 'John Doe'\n]);\n\n$og-\u003eprofile([\n    'first_name'    =\u003e 'Kim',\n    'last_name'     =\u003e 'Doe'\n]);\n```\n\n### Add Attributes\n\nFacebook supports more than just the basic object types. To add attributes for off-the-record object types you may use the `attributes` method.\n\nWithout custom validation rule:\n\n```php\n$og-\u003eattributes('product', ['product:color' =\u003e 'red']);\n```\n\nWith custom validation rule:\n\n```php\n$og-\u003eattributes('product', ['product:color' =\u003e 'red'], ['product:color']);\n```\n\nThe only validation this method performs is to check if all attribute names match with the list of attribute names.\n\n### Add A Tag Several Times\n\nA property can have multiple values. Add the tag several times to achieve this effect.\n\n```php\n$og-\u003eimage('http://example.org/apple.jpg')\n    -\u003eimage('http://example.org/tree.jpg');\n```\n\n\u003e Adding a basic tag a second time will override the value of the first tag. Basic tags must not exist several times.\n\n## Validation\n\nIf 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.\n\nValidation checks if tag values are legit and if attribute types are known.\n\nEnable validation by method:\n\n```php\n$og-\u003evalidate();\n```\n\nBy constructor:\n\n```php\n$og = new OpenGraph(true);\n```\n\nDisable validation:\n\n```php\n$og-\u003evalidate(false);\n```\n\n## Miscellaneous\n\n### Determine If A Tag Exists\n\n```php\n$hasTitle = $og-\u003ehas('title');\n```\n\n### Remove A Tag From The List\n\n```php\n$og-\u003eforget('title');\n```\n\n### Remove All Tags From The List\n\n```php\n$og-\u003eclear();\n```\n\n### Add A Custom Tag\n\n```php\n$og-\u003etag('apples', 7);\n```\n\n\u003e To disable auto-prefixing pass a third parameter: `$og-\u003etag('apples', 7, false)`\n\n### Get The Last Tag (By Name)\n\n```php\n$tag = $og-\u003elastTag('image');\n$value = $tag['value'];\n```\n\n\u003e Tags are stored as arrays consisting of name-value-pairs.\n\n## Status\n\nStatus of this repository: **Maintained**. If you create an issue you will get a response usually within 48 hours.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskonnertz%2Fopen-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchriskonnertz%2Fopen-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskonnertz%2Fopen-graph/lists"}