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);
The MetaTag library is released under the MIT license.
Any contributions or suggestions welcome. Please submit pull requests to the 'develop' branch.