danmurf/metatag

An html head meta tag generator.

2.0.0 2018-03-12 21:09 UTC

This package is auto-updated.

Last update: 2024-05-29 04:08:45 UTC


README

Build Status

A library for aggregating and generating html head meta tags. Great for MVC apps; include your meta tags in your controllers and output the result in your views.

To get started, install the library with composer:

composer require danmurf/metatag

Start up the library:

use danmurf\MetaTag;

class MyController
{
  public function index()
  {
    $metatag = new MetaTag();
    //...
  }
}

Add page keywords:

$metatag->setKeywords(['awesome', 'weblog', 'writings']);

Add a page description:

$metatag->setDescription("This weblog is about...");

Add an author tag:

$metatag->setAuthor("Jessie Wongus");

Set the page's canonical URL

$metatag->setCanonicalUrl("https://www.example.com/splendid");

If you'd rather hide the page from search engines:

$metatag->setNoindex(true);

Then add the output to your view / template to render the meta tags:

$metatag->render();

Final output:

<meta name="keywords" content="awesome, weblog, writings">
<meta name="description" content="This weblog is about...">
<meta name="author" content="Jessie Wongus">
<link rel="canonical" href="https://www.example.com/splendid">

If you like to keep your output tidy, add an indent of 4 spaces to your meta tags:

$metatag->render(4);

License

The MetaTag library is released under the MIT license.

Contributions

Any contributions or suggestions welcome. Please submit pull requests to the 'develop' branch.