1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can I get my dynamic meta tags to load for each page? (I am using Codeignitor)

Discussion in 'PHP' started by msank, Jun 1, 2012.

  1. #1
    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!
     
    Solved! View solution.
    msank, Jun 1, 2012 IP
  2. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #2
    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.
     
    kbduvall, Jun 1, 2012 IP
  3. msank

    msank Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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!
     
    msank, Jun 1, 2012 IP
  4. #4
    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:
     
    kbduvall, Jun 1, 2012 IP
  5. msank

    msank Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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!
     
    msank, Jun 4, 2012 IP
  6. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #6
    NP.
    Some of the most lengthy and destructive software bugs have been something as simple as a decimal in the wrong position. :)
     
    kbduvall, Jun 4, 2012 IP
  7. swhp

    swhp Member

    Messages:
    27
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    38
    #7
    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
     
    swhp, Nov 5, 2014 IP