CodeIgniter dynamic page title and meta description for SEO

How to set CodeIgniter dynamic page title and meta description for page SEO with common header template. Here is simple code sample given for achieving CodeIgniter SEO page title and meta description.

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.

With change in two files we can get dynamic page title and meta description page wise.
1) Language file
2) Header template file

Language file change for CodeIgniter dynamic page title and meta description

Create title and description value array in language file with specific format.

Title array format
$lang[‘/{PAGE_URL_PART}_title’] = ‘PAGE TITLE VALUE’;

Description array format
$lang[‘/{PAGE_URL_PART}_desc’] = ‘PAGE META DESCRIPTION VALUE’;

//page title array
$lang['/contact_title'] = 'Contact | SITE_NAME';
$lang['/login_title'] = 'Login | SITE_NAME';
$lang['/register_title'] = 'Register | SITE_NAME';

//page meta description array
$lang['/contact_desc'] = 'This is contact page.';
$lang['/login_desc'] = 'This is login page.';
$lang['/register_desc'] = 'This is register page.';

Header template file change for CodeIgniter dynamic page title and meta description

Access title and description value based on $_SERVER > PATH_INFO value and use in header template file.

<?php if(isset($this->lang->line($_SERVER['PATH_INFO'].'_title'))){?>
    <title><?php echo $this->lang->line($_SERVER['PATH_INFO'].'_title'); ?></title>
<?php }else{ ?>
    <title>YOUR DEFAULT TITLE</title>
<?php } ?>

<?php if(isset($this->lang->line($_SERVER['PATH_INFO'].'_desc'))){?>
    <meta name="description" content="<?php echo $this->lang->line($_SERVER['PATH_INFO'].'_desc'); ?>">
<?php } ?>

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

Above process perfect for pages which have predefined url. For dynamic url e.g., product pages which display from database and have dynamic url based on product name.

Check it out this post for CodeIgniter page SEO: Page title and meta description from database for dynamic url.

3 Comments

  1. First of all thanks for this nice trick. I was using it, but i noticed one issue with it, How do i write titles for dynamic urls ? I am trying to solve it but if you already know can you please post it here, for me as well as other visitors might also face same issue.

  2. Good article will help to many user for startup CI application, i am having an ecommerce shopping cart in CI how i will add dynamic title & description. if you have any idea so share.

    1. Thanks for appreciating work. Based on your comment new article added and detail updated in current article. I am sure, it will give you more clear idea for your requirement.

Comments are closed.