SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would I dynamically change Meta Tag Information?

    Hi Everyone,

    How would I dynamically change meta tag information on a per page basis?

    If a visit is on my "about" or "inventory" page. In the title and meta tag I would want that user to see "about us" or "inventory". How would I do something like that? Thanks!

    For example, this page should be echoing out "Title Test Page" but it's not. What am I doing wrong here?
    Thanks!

    http://whatsmyowncarworth.com/class-.../titletest.php

    PHP Code:
    <?php 
    $title

    switch(
    $_SERVER['PHP_SELF']) 

    case 
    '/index.php'
    $title 'Home'
    break; 
    case 
    '/titletest.php'
    $title 'Title Test Page'
    break; 



    echo 
    '<title>'.$title.'</title>'
    ?>

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Have you checked what $_SERVER['PHP_SELF'] is returning?

    You do not have a default option which may also give you any indications of a problem.

    I use:
    PHP Code:
    $path_parts pathinfo($_SERVER['PHP_SELF']);
    $filename basename($path_parts['basename']);
    .
    .
    .
    switch (
    $filename) {
    case 
    "index.php":
    $metaDesc "Blah blah blah";
    $metaKey "Photos";
    break;
    case 
    "contact.php":
    .
    .

    I do not like this way of doing things as it is not as easy to find errors:
    PHP Code:
    switch($_SERVER['PHP_SELF']) 

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Rubble,

    Thanks for your response but I actually just figured it out.

    This is what I think what is happening.
    The request_uri acts as a unique identifier of the page and whatever URL the user is on, the page echos out the $title variable? Is that correct?

    Thanks!

    PHP Code:
    $title;
    $url $_SERVER['REQUEST_URI'];
    switch(
    $url){

     case 
    "/class-work/sign3/titletest.php";
     
    $title 'Title Test Page!';
     break;

    etc.....
     } 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •