how to add <title> tag in php?

Discussion in 'PHP/MySql' started by bitane, Aug 8, 2011.

  1. bitane New Member

    Member Since:
    Jun 17, 2011
    Message Count:
    269
    Likes Received:
    0
    Hi,

    I have just about completed my first php website and am not sure how to add a title tag for each of the pages? I have used <title> Title </title> tag but the title is not coming up at the top of any of my pages.

    Is there another way title tags should be written when developing a site in php as to opposed from the traditional XHTML sites?
  2. MarPlo Member

    Member Since:
    May 12, 2011
    Message Count:
    66
    Likes Received:
    6
    Hy ,
    You can set a variable that store the title of the curwent page. That title can be taken from a database, or an array with titles.
    Than echo that variable within the HTML <head> area, like this:
    PHP:
    <?php
    $titl = 'Text for title';
    echo '<title>'. $titl. '</title>';
    ?>
  3. kareelasmith New Member

    Member Since:
    Sep 7, 2011
    Message Count:
    41
    Likes Received:
    0
    In PHP, title tag can be used at header,

    <title >
    <?php
    print $title;
    ?>
    </title>

    title tag can be used with meta tags at header,

    <title>
    <?php
    print $title;
    ?>
    </title>
    <meta name="keywords"
    content= "
    <?php
    print $meta_keywords;
    ?>"
    >

Share This Page