All Projects → chriskonnertz → Open Graph

chriskonnertz / Open Graph

Licence: mit
Library that assists in building Open Graph meta tags

Projects that are alternatives of or similar to Open Graph

Seo Helper
🔍 SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).
Stars: ✭ 262 (+133.93%)
Mutual labels:  laravel, seo, tags
Seotools
SEO Tools for Laravel
Stars: ✭ 2,406 (+2048.21%)
Mutual labels:  opengraph, laravel, seo
Laravelmetatags
The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
Stars: ✭ 226 (+101.79%)
Mutual labels:  opengraph, laravel, seo
All In One Seo Pack
All in One SEO Pack plugin for WordPress SEO
Stars: ✭ 281 (+150.89%)
Mutual labels:  opengraph, seo
wagtail-metadata-mixin
🔍 OpenGraph, Twitter Card and Schema.org snippet tags for Wagtail CMS pages
Stars: ✭ 42 (-62.5%)
Mutual labels:  seo, opengraph
Laravel Robots Middleware
Enable or disable the indexing of your app
Stars: ✭ 259 (+131.25%)
Mutual labels:  laravel, seo
SeoTags
SeoTags create all SEO tags you need such as meta, link, twitter card (twitter:), open graph (og:), and JSON-LD schema (structred data).
Stars: ✭ 113 (+0.89%)
Mutual labels:  seo, opengraph
Laravel Referer
Remember a visitor's original referer
Stars: ✭ 339 (+202.68%)
Mutual labels:  laravel, seo
Laravel Paginateroute
Laravel router extension to easily use Laravel's paginator without the query string
Stars: ✭ 306 (+173.21%)
Mutual labels:  laravel, seo
Laravel Missing Page Redirector
Redirect missing pages in your Laravel application
Stars: ✭ 378 (+237.5%)
Mutual labels:  laravel, seo
Laravel Tags
Add tags and taggable behaviour to your Laravel app
Stars: ✭ 1,026 (+816.07%)
Mutual labels:  laravel, tags
magento2-module-seo
Magento 2 Module for Search Engine Optimization
Stars: ✭ 100 (-10.71%)
Mutual labels:  seo, opengraph
11r
America's favorite Eleventy blog template.
Stars: ✭ 135 (+20.54%)
Mutual labels:  tags, seo
Yoast Seo For Typo3
Yoast SEO plugin for TYPO3
Stars: ✭ 43 (-61.61%)
Mutual labels:  opengraph, seo
Lashop
Simple shop based on Laravel 7.3
Stars: ✭ 60 (-46.43%)
Mutual labels:  laravel, seo
seo-fu
📖 A simple HTML file filled with tags and documentation
Stars: ✭ 25 (-77.68%)
Mutual labels:  tags, seo
The Seo Framework
The SEO Framework WordPress plugin.
Stars: ✭ 329 (+193.75%)
Mutual labels:  opengraph, seo
Laravel Sitemap
Create and generate sitemaps with ease
Stars: ✭ 1,325 (+1083.04%)
Mutual labels:  laravel, seo
Meter
Laravel package to find performance bottlenecks in your laravel application.
Stars: ✭ 204 (+82.14%)
Mutual labels:  graph, laravel
Laravel Open Source Projects
A Web Artisan list of categorized OPEN SOURCE PROJECTS built with Laravel PHP Framework.
Stars: ✭ 676 (+503.57%)
Mutual labels:  open, laravel

Open Graph Builder

Build Status Monthly Downloads Version GitHub license

Library that assists in building Open Graph meta tags.

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 >=7.0.

Framework Support

Laravel >=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 >=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

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. Read the documentation to learn more about the tags that are available and the values they support or check out 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 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 strings.

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

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

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

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

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

Determine If A Tag Exists

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

Remove A Tag From The List

$og->forget('title');

Remove All Tags From The List

$og->clear();

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)

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

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

Status

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].