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. I have my header.php with this code directly after the opening head tag: <?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);?> Code (markup): 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: <?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 Code (markup): Any thoughts, or ideas on this matter, please? Thanks so much!
I assume header.php is loaded before your other pages. If so, it looks like your custom meta tags for your other pages are being assigned AFTER your default meta tags are assigned and displayed in your header. I'd check to see if there's a better place to put <?= meta($meta); ?> so that it's called after your custom meta tags are assigned.
If I am understanding you correctly, then, nope... I am assigning the unique meta tags before I even include the header.php file, on each individual page... If I am misunderstanding you, then please let me know! Thanks!
It's been a few years since I've used CI, but it looks like it may be a scope issue. A view only has access to the variables you pass to it so header.php doesn't see $meta since you don't pass meta to it when you load the header. Try something like this: <?php $data['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', $data); ?> PHP:
Keith: Der... It figures it would be something simple like that! Always is. Thanks so much for being my extra eyes! It works perfectly now! Yay!
NP. Some of the most lengthy and destructive software bugs have been something as simple as a decimal in the wrong position.
Hello, i'm also looking for this. But how to implements meta for posting page. Because i want to make CMS use codeigniter and i still don't know about meta description in dinamic page thank you