Jump to content

Trying to set Webpage Title dynamically


TomTees

Recommended Posts

I am trying to set the HTML Page Title dynamically, but this code from my book doesn't work...

 

			<title>
			<?php
				// Dynamically set Page Title.
				if (isset($page_title)){
					echo $page_title;
				} else {
					// Default Page Title.
					echo 'Knowledge is Power: And It Pays To Know';
				}
			?>
		</title>

 

What is wrong with it?

 

(All I see is the code in the Webpage/Window Title...)

 

 

 

TomTees

 

 

Link to comment
Share on other sites

Does your webpage end in .php?  i.e. index.php, page.php, etc.?

 

Is the PHP engine supplied to you?  Are you using a 'free webhosting' website?  If so, what company?

 

Your code is correct, though I'm not a fan of your formatting (then again we each have our own style).

Link to comment
Share on other sites

Does your webpage end in .php?  i.e. index.php, page.php, etc.?

 

Is the PHP engine supplied to you?  Are you using a 'free webhosting' website?  If so, what company?

 

Your code is correct, though I'm not a fan of your formatting (then again we each have our own style).

 

I am using NetBeans on my laptop.

 

The author said to call the page "header.html"

 

What is wrong with my formatting?

 

 

TomTees

 

 

Link to comment
Share on other sites

Well, there's your problem.  You need a .php page in order for the php engine to recognize it's a page to be rendered by PHP.  Change the extension from .html to .php and you'll see it in the title.

 

Maybe your author was/is going to have the header as an include?  i.e. have an index.php page and inside that page do

include('header.php');

or

include_once('header.php');

Link to comment
Share on other sites

Well, there's your problem.  You need a .php page in order for the php engine to recognize it's a page to be rendered by PHP.  Change the extension from .html to .php and you'll see it in the title.

 

Maybe your author was/is going to have the header as an include?  i.e. have an index.php page and inside that page do

include('header.php');

or

include_once('header.php');

 

Yeah, I figured that out while you guys were responding.  I placed the code in test.php and it ran/looks fine.

 

The author is indeed making me create a header.html file that will ultimately be included in a php file but I'm not that far in my book yet!  :D

 

Thanks,

 

 

 

TomTees

 

P.S.  Feel free to answer this post if you know the answer...

 

http://www.phpfreaks.com/forums/php-coding-help/help-setting-up-path-constants/

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.