How to use php to set title
function set_page_title(){
global $page_title;
/*
you should make the variable global so the function can access it and set it to the page title
otherwise you will get an error.
*/
if(isset($page_title)){ /*Check if my code has that variable*/
echo $page_title;
}
else{
echo "Page Title";
}
}
/*
HTML Layout
<!DOCTYPE html>
<head>
<title><?php set_page_title() ?></title>
</head>
...
*/
4
8
//1. Simply add $title variable before require function
<?php
$title = "Your title goes here";
require("header.php");
?>
//2. Add following code into header.php
<title><?php echo $title; ?></title>
Thank you!
8
0
Are there any code examples left?
New code examples in category PHP