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
- Host: GitHub
- URL: https://github.com/pedroborges/meta-tags
- Owner: pedroborges
- Created: 2017-02-28T14:32:31.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-03T05:21:48.000Z (over 7 years ago)
- Last Synced: 2025-10-04T07:51:02.032Z (5 months ago)
- Topics: head, json-ld, meta-tags, open-graph, php, schema, seo, twitter-cards
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 45
- Watchers: 5
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
Awesome Lists containing this project
README
# PHP Meta Tags [](https://github.com/pedroborges/meta-tags/releases) [](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>