Dynamic page title in PHP

 Dynamic page title in PHP 

  • A dynamic page title is a title tag for a web page that changes dynamically based on certain conditions or variables.
  • The title tag is an essential HTML element that defines the title of a document.
  • It is displayed on the browser's title bar or tab and is also used by search engines to understand the content of the page.
  • In PHP, you can dynamically set the page title by using a variable to hold the title value and echoing it within the HTML `<title>` tag.

 

example:  index.php:

 

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

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

</head>

<body>

    <h1>Welcome to my website</h1>

    <p>This is a dynamic page with a dynamic title.</p>

</body>

</html>

  

 Dynamic Page Title in PHP (example.php):

 

php

<?php

// Set the dynamic page title

$pageTitle = "Example Page";

 

// Include the common header

include 'header.php';

?>

 

<!-- Additional content for the example page -->

<p>This is the content of the example page.</p>

 

<?php

// Include the common footer

include 'footer.php';

?>

 

 Dynamic Page Title in PHP (about.php):

 php

<?php

// Set the dynamic page title

$pageTitle = "About Us";

 

// Include the common header

include 'header.php';

?>

 

<!-- Additional content for the about page -->

<p>Learn more about our company and team.</p>

 

<?php

// Include the common footer

include 'footer.php';

?>

 

Post a Comment

0 Comments