SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast rekha_shp's Avatar
    Join Date
    Jan 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically give title for pages

    Hi,

    I want to give title dynamically for every pages.I have a header.php page where I put the title as follows,

    Code:
    <title><?php if (defined ('TITLE')) {
    print TITLE;
    }
    ?></title>
    In every page I defined the title as

    Code:
    define ('TITLE', title goes here');
    It is working fine for me.But I don't know whether it gets indexed or google will ignore it.Or Is there any better sloution to change the title dynamically.Pls help.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The php code is server side only, google etc will never know it exists. You can use view->source in a browser to see what is being rendered (what browsers and bots see).

  3. #3
    SitePoint Enthusiast rekha_shp's Avatar
    Join Date
    Jan 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In view source the title is displaying inside head tag only.I am asking that is this correct way of coding or we have some simple techniques or so.

    Pls help.

  4. #4
    ********* Staff mattevans's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi rekha_shp,

    hash is right. When someone visits your site, multiple calls to the server are made to get the website. Basically, the server will render (read) the code, and send a web page back to the user (their browser). Whatever you see, or I see when the page loads, is what the different bots will read/index.

    In regards to your second post, the <title> tag should sit within your <head> tag. So in the source you should see something like...

    <html>
    <head>
    <title>Title Goes Here!</title>
    </head>
    Matt Evans
    Sitepoint Developer
    tweet 2 me

  5. #5
    SitePoint Enthusiast rekha_shp's Avatar
    Join Date
    Jan 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So there will be no issue if i give title tag using php code stated in my first post.Google will index my site correctly with proper title.Am I right?

  6. #6
    ********* Staff mattevans's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's right!
    Google will index it as normal.
    Matt Evans
    Sitepoint Developer
    tweet 2 me

  7. #7
    SitePoint Enthusiast rekha_shp's Avatar
    Join Date
    Jan 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

  8. #8
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If title is not defined you'll be writing an empty <title> tag. You might want a default.

    <title><?php
    if(defined('TITLE')) echo TITLE;
    else echo 'The name of my website';
    ?></title>

  9. #9
    SitePoint Enthusiast rekha_shp's Avatar
    Join Date
    Jan 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya.Right.I have given the default title.I forget to mention it here.Thanks.


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
  •