Dynamic Meta Tag

I am doing a project in Yii framework now. i am concern about title tag and other meta tag which will be dynamic as well for SEO propose , The data for the tags will be fetched from database and displayed in the front-end.

What Should be my approach ?

Thanks in advance

1 Like

You may declare meta tags as main Controller properties and to set their values, for example at beforeRender() method.



        <meta name="keywords" content="<?php echo CHtml::encode($this->keywords)?>" />

        <meta name="description" content="<?php echo $this->description?>" />



 	* @var string meta tag keywords content 


    public $keywords = '';


 	* @var string meta tag description content 


    public $description = '';


 	* This method is invoked at the beginning of {@link render()}.

 	* @param string $view the view to be rendered

 	* @return boolean whether the view should be rendered.


    protected function beforeRender($view)


        list($keyword, $description) = Yii::app()->seoHelper->findMetaTags();

        $this->keywords = $keyword ? $keyword : Yii::app()->settings->get('meta', 'keywords');

        $this->description = $description ? $description : Yii::app()->settings->get('meta', 'description');

        return parent::beforeRender($view);


For title there’s a yii pageTitle. You may overwrite [size=“2”]getPageTitle() with your own implementation.[/size]

I think you should creat new database table , and get this table to front-end .

Creat a table :


-META tag:

–meta title

–meta des

–meta tag

–meta robots

–meta property ( important for seo richsnippest)

-REL tag




And then , use same code get in Yii !