An open API service indexing awesome lists of open source software.

https://github.com/pedroborges/meta-tags

HTML meta tags generator for PHP. Supports Open Graph, Twitter Cards, and JSON Linked Data out of the box
https://github.com/pedroborges/meta-tags

head json-ld meta-tags open-graph php schema seo twitter-cards

Last synced: 5 months ago
JSON representation

HTML meta tags generator for PHP. Supports Open Graph, Twitter Cards, and JSON Linked Data out of the box

Awesome Lists containing this project

README

          

# PHP Meta Tags [![Release](https://img.shields.io/github/release/pedroborges/meta-tags.svg)](https://github.com/pedroborges/meta-tags/releases) [![Issues](https://img.shields.io/github/issues/pedroborges/meta-tags.svg)](https://github.com/pedroborges/meta-tags/issues)

HTML meta tags generator for PHP. Supports [Open Graph](http://ogp.me), [Twitter Cards](https://dev.twitter.com/cards/overview), and [JSON Linked Data](https://json-ld.org) out of the box.

## Installation

composer require pedroborges/meta-tags

## Basic Usage
Create a new `MetaTags` instance then you are ready to start adding meta tags:

```php
use PedroBorges\MetaTags\MetaTags;

$tags = new MetaTags;

// My Awesome Site
$tags->title('My Awesome Site');

//
$tags->meta('description', 'My site description');

//
//
$tags->link('canonical', 'https://pedroborg.es');
$tags->link('alternate', [
'hreflang' => 'en',
'href' => 'https://en.pedroborg.es'
]);

//
//
//
//
$tags->og('title', 'The title');
$tags->og('type', 'website');
$tags->og('url', 'https://pedroborg.es');
$tags->og('image', 'https://pedroborg.es/cover.jpg');

//
//
$tags->twitter('card', 'summary');
$tags->twitter('site', '@pedroborg_es');

//
// {
// "@context": "http://schema.org",
// "@type": "Person",
// "name": "Pedro Borges"
// }
//
$tags->jsonld([
'@context' => 'http://schema.org',
'@type': 'Person',
'name': 'Pedro Borges'
]);
```

When you are ready to output them, use the `render` method inside your template `` element:

```php



render() ?>
```

You can also render only one tag:

```php
render('title') ?>
```

Or specify which tags to render:

```php
render(['og', 'twitter', 'json-ld']) ?>
```

By default Meta Tag will indent the tags with 4 spaces and use the following order:

1. ``
1. `` (General)
1. `` (Open Graph)
1. `` (Twitter Cards)
1. ``
1. `` (JSON-LD)

You can change that when instantiating the `MetaTag` class:

```php
use PedroBorges\MetaTags\MetaTags;

$tags = new MetaTags("\t", ['meta', 'title', 'link', 'og', 'twitter', 'json-ld']);
```

## Change Log
All notable changes to this project will be documented at: <https://github.com/pedroborges/meta-tags/blob/master/changelog.md>

## License
Meta Tags is open-sourced software licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).

Copyright © 2018 Pedro Borges <oi@pedroborg.es>