PHP code need for adding dynamic meta tags of a php site

Discussion in 'PHP' started by iampapan, Dec 12, 2012.

  1. #1
    Last edited: Dec 12, 2012
    iampapan, Dec 12, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    You want to add meta tags to a URL? Or to the sites at those URLs?

    Where is the data for the tags coming from?
     
    Rukbat, Dec 12, 2012 IP
  3. iampapan

    iampapan Active Member

    Messages:
    110
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Hi Rukbat,
    Meta tags will be shown in source code of every dynamic page. Data tag coming from txt file.

    Thanks,
    Papan
     
    iampapan, Dec 12, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    Something like (data in the text file is separated by %):
    
    $title='my title';
    $handle = fopen($myFile, 'r');
    if($handle) {
      $tags = explode('%', fgets($handle));
      echo '<meta name="title" content="'.$title.'"><br />';
      echo '<meta name="description" content="'.$tags[0].'"><br />';
      echo '<meta name="keyword" content="'.$tags[1].'"><br />';
      fclose($handle);
    }
    
    PHP:
    You could put the code in the 'if' into a while loop, with a value for the page name or number and, if that's the current page, write the meta tags. Then you could have one line in the text file per page. Everyone does this sort of thing differently; do something that's comfortable for you.
     
    Rukbat, Dec 13, 2012 IP
  5. iampapan

    iampapan Active Member

    Messages:
    110
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #5
    Thanks for this code. I will use it today and send you feedback
     
    iampapan, Dec 13, 2012 IP
  6. johnaustin9

    johnaustin9 Member

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    Create C-panel for your site and given an option for title and description..
     
    johnaustin9, Dec 14, 2012 IP