chaseman Posted January 15, 2011 Share Posted January 15, 2011 I have a header.php, which I include in all my pages, but I'd like to have an individual title for all pages for better SEO - how can I do that? Explanation: header.php <!DOCTYPE> <head> <title>MyWebsite </title> </head> <body> And I would like to have something like this: header.php <!DOCTYPE> <head> <title>MyWebsite | $InsertPageTitle </title> </head> <body> And then: example.php include('header.php'); $InsertPageTitle = "Contact Form"; I tried this exact method, unfortunately it didn't work, so how can I make it work? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/ Share on other sites More sharing options...
denno020 Posted January 15, 2011 Share Posted January 15, 2011 <!DOCTYPE> <head> <title>MyWebsite | <?php $InsertPageTitle ?> </title> </head> <body> Have a crack at that buddy. You need to jump into php so the browser (or whatever is creating the page) knows that it's in fact a php variable that you want, not just the text that read $InsertPageTitle. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159630 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 You need to define the variable before you include the file that will use it. Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159632 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2011 Share Posted January 15, 2011 And you need to echo php variables to get their content to be output to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159634 Share on other sites More sharing options...
denno020 Posted January 15, 2011 Share Posted January 15, 2011 You need to define the variable before you include the file that will use it. It took me a minute to understand what you meant, so I though I would post some code to illustrate your meaning, so it's easy for the OP and anyone else to see what to do. example.php //declare the variable $InsertPageTitle = "Contact Form"; //before you use it in the following file include('header.php'); Correct me if I'm wrong, but I think this is what Pikachu2000 is referring to? Denno Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159635 Share on other sites More sharing options...
The Eagle Posted January 15, 2011 Share Posted January 15, 2011 <?php include ("pagetitles.php"); ?> <HTML> <HEAD> <title>MyWebsite | <?php echo $page1; ?></title> Then in the pagetitles.php, <?php // page titles $page1 = "Home"; $page2 = "About"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159636 Share on other sites More sharing options...
chaseman Posted January 15, 2011 Author Share Posted January 15, 2011 You need to define the variable before you include the file that will use it. This was the mistake I was doing. I did the <?php echo ?> thing, I just forgot to do it in the example, it was late night, sorry about that. But the mistake I was doing was: include('header.php'); $pagetitle = "Contact Form"; Instead it should be: $pagetitle = "Contact Form"; include('header.php'); I just tried it and now it works, thanks to all. Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159729 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2011 Share Posted January 15, 2011 I just forgot to do it in the example You should be copy/pasting the ACTUAL code you need help with. There's no reason you should be wasting your time TYPING your code into a post. Quote Link to comment https://forums.phpfreaks.com/topic/224483-have-each-page-title-in-the-header/#findComment-1159731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.