CodeIgniter page SEO: Page title and meta description from database for dynamic url

CodeIgniter page SEO: Page title and meta description from database for dynamic url with common header template. CodeIgniter SEO page title and meta description set based on dynamic url and related page content.

CodeIgniter page SEO - Page title and meta description from database for dynamic url
CodeIgniter page SEO-Page title and meta description from database for dynamic url

Here is solution for all below queries: Facing a problem implementing SEO, title and descriptions, CodeIgniter – Displaying and entering dynamic meta data and How can I get my dynamic meta tags to load for each page.

This article is for solve problem with dynamic url page seo. Mostly in product based website, url create dynamically for product. Vevlo get this type of problem comment in previously written article. i.e., “CodeIgniter dynamic page title and meta description for SEO”

Let’s start CodeIgniter page SEO step by step.
1) Prepare page title, meta description and set for template in controller file
2) Use dynamic meta title, meta description in Header template file

Prepare page title, meta description and set for template in controller file

Suppose you want to set seo data for product main page. Prepare page title, meta description and set in array. You can also make helper function that will return array of title, description based on passed database parameter value.

//$productRow is database row of product
$data['page_title'] = $productRow->name.' | SITE_NAME';

//Here short_desc is more detail for product/page content
$data['meta_desc'] = $productRow->name.' '.$productRow->short_desc;

//pass $data array to template or
//if you use common function for set view, pass it with other parameter
$this->load->view('header', $data);

Use dynamic page title, meta description in Header template file

Access title and description value from passed view data array and use in header template file.

<?php if(!empty($page_title)){?>
    <title><?php echo $page_title; ?></title>
<?php }else{ ?>
    <title>YOUR DEFAULT TITLE</title>
<?php } ?>

<?php if(!empty($meta_desc)){?>
    <meta name="description" content="<?php echo $meta_desc; ?>">
<?php } ?>