how to use php to set title

Solutions on MaxInterview for how to use php to set title by the best coders in the world

showing results for - "how to use php to set title"
Alberto
17 Jun 2016
1function set_page_title(){
2  global $page_title; 
3  /*
4    you should make the variable global so the function can access it and set it to the page title
5    otherwise you will get an error.
6  */
7  if(isset($page_title)){ /*Check if my code has that variable*/
8    echo $page_title;
9  }
10  else{
11    echo "Page Title";
12  }
13}
14/*
15  HTML Layout
16  <!DOCTYPE html>
17  <head>
18    <title><?php set_page_title() ?></title>
19  </head>
20  ...
21*/
Juan Manuel
13 Mar 2020
1//1. Simply add $title variable before require function
2<?php
3
4$title = "Your title goes here";
5require("header.php");
6
7?>
8  
9  
10//2. Add following code into header.php
11
12<title><?php echo $title; ?></title>
13