user3476448
user3476448

Reputation: 11

HTML metadata after <head> tag

I'm creating a PHP website that has one index.php file and instead of having files something.php, about.php, contact.php I have set it up as the following: index.php?p=something, index.php?p=contact etc.

Currently my index.php code looks like this:

<head>
   <title>Something</title>
   <link href="theme.css" rel ="stylesheet" media="screen">
</head>

<body>
<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
</body>

Now the problem is that I want to have different metadata in index.php, something.php and about.php. I know I have to add metadata between <head></head>, but something.php and about.php are included later. How can I have different metadatas for the files? Is it possible to (re)set metadata after <head></head> tags?

Upvotes: 0

Views: 565

Answers (3)

hassan
hassan

Reputation: 8288

in your index.php

<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
?>

and in your about.php, something.php include the full html page included it's head tag

Upvotes: 1

umlal
umlal

Reputation: 9

Try loading the metadata according to your preferences,as such:

<head>
   <title>Something</title>
   <link href="theme.css" rel ="stylesheet" media="screen">
   <?php if (@$_GET['p'] == 'something') echo "<meta charset='utf-8'>"; ?>
</head>

<body>
<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
?>
</body>

Upvotes: 1

vaso123
vaso123

Reputation: 12391

I do not know, do I understood your question, but of course, you can use your if condition in the header too!

<head>
    <title>Something</title>
    <link href="theme.css" rel ="stylesheet" media="screen">
    <?php
        if ($_GET["p"] === 'something') {
            ?>
    <!-- Write your metadata here if the page is something... -->

    <?php
        } elseif ($_GET["p"] === 'about') {
        ?>
    <!-- Write your metadata here if the page is about... -->
    <?php
        }
    ?>
</head>

<body>
    <?php
    if ($_GET['p'] == 'something') {
        include 'pages/something.php';
    } elseif ($_GET['p'] == 'about') {
        include 'pages/about.php';
    }
    ?>
</body>

Upvotes: 1

Related Questions