0

I would like to give a title to each of my pages, but all my pages are linked to my index.php:

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="UTF-8">
        <title>Test</title>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <?php include("top_bar.php");?>
        <?php include("header.php");?>
        <?php include("container.php");?>
        <?php include("footer.php");?>
    </body>
</html>

Here is how my site is: http://prntscr.com/47nn7h

All my pages have the title I put for index.php, but how to add a title to a specific page (example, when I go to the page members.php)?

members.php:

<?php include "index.php";?>

Thanks.

  • 1
    You could build a conditional title string with PHP based on the page you are viewing. Then display that string in the `` tag. How do you include specific page content? Is there a variable to indicate which page to show? (e.g. `$page='members';`) – showdev Jul 29 '14 at 23:50
  • if they are not separate pages, then you should change the title of your index accordingly – epipav Jul 29 '14 at 23:51
  • I would like the title changes automatically depending on the page where I am. I have members.php, sign_up.php, sign_in.php pages. How can I place the title for each pages? –  Jul 29 '14 at 23:58
  • No, I don't have. All pages are based on my index.php page. I really don't know how can I put a title for each of my pages. –  Jul 30 '14 at 00:03
  • I suggest reversing your logic so that all pages run off of `index.php`. Instead of including `index.php` from `members.php`, include `members.php` from `index.php` when `$page=='members'`. That way you can use `$page` to conditionally set a title string for each page. – showdev Jul 30 '14 at 00:04
  • Problem fixed, I used this method: Test –  Jul 30 '14 at 00:07

2 Answers2

2

Replace the existing <title> tag with this.

<title><?php echo $pagetitle; ?> </title>

in your <head> block.

Make sure that $pagetitle actually contains the desired title before you emit the tag. It's not clear from your question where these titles are coming from - you'll probably need some PHP right at the top of the page to set all this up. .

0

You could use this method and add the

$pageTitle = 'Title of Page';

to your content page (i.e. member page)

Community
  • 1
  • 1
Bijan
  • 7,737
  • 18
  • 89
  • 149