Welcome Guest, Not a member yet? Register   Sign In
How can I get my dynamic meta tags to load for each page?
#1

[eluser]msank[/eluser]
Hi guys,

I am trying to have unique meta tags for each page. So far, what I have done is only loading the DEFAULT meta tags, and I just can't see why it isn't working. Sad

I have my header.php with this code directly after the opening head tag:

Code:
<?php
if(!isset($meta)) {
$meta = array(
                 array('name'=>'description', 'content'=>'A short but sweet DEFAULT description of this fine site'),
                 array('name' =>'keywords', 'content'=>'some awesome DEFAULT keywords for those rascally web crawlers')
        );
}
?>
<?php
$this->load->helper('html');
?>

more php here.....
.....
.....
.....
<title>
...
</title>

<link rel="shortcut icon" type="image/x-icon" href="img/fav.ico">
<meta charset="UTF-8" />

<!--This is where I am calling the meta function-->
<?php echo meta($meta);?>

And then this is what I am putting in all of my pages (except for my header.php, of course!), before I include the header:

Code:
<?php
$meta = array(
                array('name'=>'description', 'content'=>'Another short but sweet description'),
                array('name' =>'keywords', 'content'=>'Mmmmm. Yummy keywords for you to savor')
       );

$this->load->view('includes/header');
?>

html stuff goes here

Any thoughts, or ideas on this matter, please?

Thanks so much!
#2

[eluser]TWP Marketing[/eluser]
What is the meta() function? Is that native php or your own code? I don't see it in the php 5 function set, so I assume you wrote it...
#3

[eluser]msank[/eluser]
It's a CI html helper function.
#4

[eluser]TWP Marketing[/eluser]
Ok, (Duh!) I've never bothered to use that helper function, but the problem is the sequence in which your code is executed. The default values are the last ones being set and therefore override anything set before.

I think a lot of your code could/should be moved to a controller, rather than the view, but that is a matter of style and not function.

Set the default meta values in the controller and the unique meta values in your view. This isn't the best way to handle it, but you'd need to rethink your MVC design to move code out of the view and into controllers and models.
#5

[eluser]msank[/eluser]
Thanks for the help! I have gotten it working. It <i>was</i> the order in which I had things.

I know the code could be done better, but I am just now getting my hands on it, as it is a "pass me down"... I inherited it from a previous developer at my company.

Thanks for the ideas and help!




Theme © iAndrew 2016 - Forum software by © MyBB