What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set each page’s title and description before it includes the shared header, then have the header print those values inside the document’s <head>. Use ordinary PHP variable names such as $pageTitle—not $page-title, where the hyphen is parsed as subtraction.

Set metadata before including the header

The shared header can output page-specific metadata only if the values have already been assigned when PHP reaches the include. For a manually maintained site, assign the values near the start of each page, then include the header:

<?php
// about.php
$pageTitle = 'About us';
$pageDescription = 'Learn about our team and what we do.';
require __DIR__ . '/header.php';
?>

In header.php, use those variables in the document head. Fallbacks let pages that have not assigned metadata render without an undefined-variable warning; escaping protects the HTML text and attribute contexts:

<head>
    <title><?= htmlspecialchars($pageTitle ?? 'Default title', ENT_QUOTES, 'UTF-8') ?></title>
    <meta name="description" content="<?= htmlspecialchars($pageDescription ?? '', ENT_QUOTES, 'UTF-8') ?>">
</head>

Choose a meaningful default title and description if a blank description is not appropriate for your site. If the page’s metadata comes from a database, retrieve the current page’s record and assign its values before requiring the header.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why $page-title does not work

A hyphen is not allowed as part of a conventional PHP variable name. PHP treats it as the subtraction operator, so an expression such as $page-title is interpreted as a variable minus another identifier—not as one variable named “page-title.” Use a valid name such as $pageTitle or $page_title instead. The PHP manual confirms that variable names are case-sensitive, so $pageTitle and $pagetitle are different variables: PHP: Basics of variables.

Use the exact same spelling and capitalization where you assign and output each value. If you see an undefined-variable warning, check both that the assignment ran and that it appears before the header include. The original question and discussion of these patterns appear in the SitePoint Forums thread.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use a description tag, not a keywords tag

Put the page’s summary in a description meta element. It is a separate field from keywords; adding a keywords tag is not necessary to make page titles and descriptions unique. Write a concise, accurate description that reflects the particular page rather than reusing the same text across the whole site.

A meta description is not a guaranteed search-result snippet. Google says snippets are primarily created from page content, may vary by search, and can use a meta description when it better describes the page: Google Search Central: Control your snippets in search results. Treat the description as useful page metadata, not a promise about the exact wording Google will show.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the include order and rendered HTML

  1. In each page, assign the page-specific title and description before the line that requires or includes the shared header.
  2. In the header, output the title inside <title> and the description in <meta name="description">.
  3. Use valid, consistently capitalized PHP variable names and provide sensible fallback values for pages without custom metadata.
  4. Load the page in a browser and inspect its source to confirm the rendered title and description are the values intended for that page.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.