#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    6

    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". I've written some below sample code but it's not working. Not sure what I'm doing.

    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-work/sign3/titletest.php

    PHP Code:
    <?php 
    $title
    ;  
    switch(
    $_SERVER['PHP_SELF']) 

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



    print 
    '<title>'.$title.'</title>'
    ?>
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,110
    Rep Power
    9398
    We don't know how your system works. We don't know how that script you posted affects anything. We don't know how the actual "about us" or "inventory" pages are loaded. We don't know how they're rendered.

    If you want good advice then you'll have to explain how your entire website works. And I don't mean your business model. I mean what the code does.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    What makes you think $_SERVER['PHP_SELF'] is /titletest.php? Did you print it out?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    6
    Hey Guys,

    Thanks for your responses. I actually figured it out.

    <?php
    $title;
    $url = $_SERVER['REQUEST_URI'];
    switch($url){

    case "login.php";
    $title = 'Login Page';
    break;

    echo "$title";
    ?>
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    You're missing a closing curly brace.

    Glad you seem to have it figured out.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo