Eugenio Goryaev
Desarrollo, soporte y optimización

floor12/yii2-metamaster Add all SEO meta and OpenGraph tags to your app with a few line of code

Build Status Scrutinizer Code Quality Latest Stable Version Latest Unstable Version Total Downloads License

This is a component for generating some Meta, Open Graph and Twitter-card tags in a template header of Yii2 app.

This is a list of supported tags:

  • canonical
  • head title
  • meta description
  • meta keywords
  • og:sitename
  • og:type
  • og:url
  • og:title
  • og:description
  • og:image
  • og:image:width
  • og:image:height
  • twitter:card
  • twitter:domain
  • twitter:site
  • twitter:description
  • twitter:image:src
  • itemprop:name
  • itemprop:image


Just run:

$ composer require floor12/yii2-metamaster

or add this to the require section of your composer.json.

"floor12/yii2-metamaster": "dev-master"

After that, include some basic metamaster data into the components section of application config.

    'components' => [
        'metamaster' => [
            'class' => 'floor12\metamaster\MetaMaster',
            'siteName' => 'My cool new Web Site',
            'defaultImage' => '/design/export_logo.png',


  1. siteName - the name of the project to show in Open Graph tags;
  2. defaultImage - web relative path to default image for Open Graph tags;
  3. web - yii2 alias to web path to reading image width and height for Open Graph tags (default is @app/web)
  4. protocol - default protocol to generate links (default is https)


It's possible to use in any place of your app. Just use setters and then call the register(View $view) method with View object passed into it.

Allowed setters:

Metamaster::setSiteName(string $value)
Metamaster::setTitle(string $value)
Metamaster::setUrl(string $value)
Metamaster::setType(string $value)
Metamaster::setDescription(string $value)
Metamaster::setImage(string $relativePath, string $absolutePath = null)

For example, using in controller:

public function actionIndex()
                   ->setTitle("This is test page")
                   ->setDescription("This is page description")

        return $this->render('index');

It will generate all you need in template:

<title>This is test page</title>
<link href="" rel="canonical">
<meta name="description" content="This is page description">
<meta property="og:site_name" content="My cool new Web Site">
<meta property="og:type" content="article">
<meta property="og:url" content="">
<meta name="twitter:card" content="summary">
<meta name="twitter:domain" content="">
<meta name="twitter:site" content="My cool new Web Site">
<meta property="og:title" content="This is test page">
<meta itemprop="name" content="This is test page">
<meta property="og:description" content="This is page description">
<meta name="twitter:description" content="This is page description">
<meta property="og:image" content="">
<meta property="twitter:image:src" content="">
<meta itemprop="image" content="">