Welcome Guest, Not a member yet? Register   Sign In
Customizing Title and Meta Tag for SEO
#5

[eluser]TWP Marketing[/eluser]
Bob I set the content of the meta tags in my controller functions. I have one view field which is used for all pages and the content of each meta element is set in that controller, depending on which page is needed. The is that view:
Code:
<?php
echo "<META http-equiv='Content-Type' content='text/html; charset=utf-8' />"."\n";
echo "<TITLE>".$html_title."</TITLE>"."\n";
echo "<META name='title' content='".$meta_title."' />"."\n";
echo "<META http-equiv='expires' content='".$expires."' />"."\n";
echo "<META http-equiv='pragma' content='".$pragma."' />"."\n";
echo "<META name='author' content='".$meta_author."' />"."\n";
echo "<META name='keywords' lang='en-us' content='".$meta_keywords."' />"."\n";
echo "<META name='description' content='".$meta_description."' />"."\n";
echo "<META name='ROBOTS' content='".$meta_robots."' />"."\n"; // robots page directive
echo "<base href=".base_url()." />";

echo "<style type='text/css' media='all'>@import url('css/twpd.css');</style>"."\n";
echo "<link rel='stylesheet' type='text/css' media='all' href='css/twpd.css' />"."\n";

/* End of file ./application/views/twpd/page_header.php */
In the controller I set a default value for each meta element and then override any elements which are needed for a particular page

Controller:
Code:
...These are default values
public function load_html_view_data()
{
   // set html header defaults
  $this->view_data['html_title']       = $this->view_data['page_name'].'- TWP Marketing™ - Goods, Services and Advice';
  $this->view_data['expires']          = "-1";
  $this->view_data['pragma']           = "no-cache";
  $this->view_data['meta_title']       = "Goods, Services and Advice";
  $this->view_data['meta_author']      = "TWP Marketing™";
  $this->view_data['meta_keywords']    = "";
  $this->view_data['meta_description'] = "TWP Marketing™ - Goods, Services and Advice";
  $this->view_data['shortcut_icon']    = '<link rel="shortcut icon" href="http://twpmarketing.com/favicon.ico" type="image/x-icon">';
  return;
}
...


For a specific page, I overwrite a few of the meta elements, for example in my page on SEO information, this is the code which sets the meta elements:
Code:
...
public function seo()
{
   // set page name
  $this->view_data['page_name'] = 'seo';

   // load advertising for side panel
  $this->view_data['ad_list'] = $this->load->view('ad_list',$this->view_data,TRUE);

   // get data specific to page_name
  $this->load_html_view_data();

[b]   // override default view data
  $this->view_data['meta_keywords']    = 'TWP Marketing™, Search Engine Optimization, seo';
  $this->view_data['meta_description'] = 'Search Engine Optimization';
  $this->view_data['meta_title']       = "Search Engine Optimization";
  $this->view_data['meta_robots']      = $this->view_data['all_robots'];[/b]

   //load views into data array
  $data = $this->load_template_views();

   // create page html and send to browser for display
  $this->load->view('page_template', $data);
  return;
}
...

Does this answer your question? There are many other ways to approach this.


Messages In This Thread
Customizing Title and Meta Tag for SEO - by El Forum - 07-15-2012, 01:22 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-15-2012, 03:39 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-16-2012, 10:14 AM
Customizing Title and Meta Tag for SEO - by El Forum - 07-16-2012, 10:28 AM
Customizing Title and Meta Tag for SEO - by El Forum - 07-16-2012, 10:37 AM
Customizing Title and Meta Tag for SEO - by El Forum - 07-16-2012, 01:44 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-16-2012, 06:28 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-17-2012, 03:40 AM
Customizing Title and Meta Tag for SEO - by El Forum - 07-17-2012, 08:27 AM
Customizing Title and Meta Tag for SEO - by El Forum - 07-17-2012, 09:07 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-17-2012, 10:51 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-17-2012, 11:27 PM
Customizing Title and Meta Tag for SEO - by El Forum - 07-18-2012, 04:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB