So, you have planned o launch a website and it will probably have thousands of pages. That sounds great so, hopefully you are going to develop the website in PHP right? Because if you have decided to develop the website in plain HTML, it means you will have to go through all the web pages in case you might have to change something in the header section like – adding a new menu or changing the footer text.
This is the reason why most of us prefer to develop website in PHP as this enables us to create separate header and footer files and fetching those files in all web pages by using PHP’s popular include function.
But the main problem that most of us have to face is to write unique Meta data for each single PHP page. Since we will be using the same header and footer file against all web pages, all pages are going to have the same Title and Meta Description tag.
From SEO’s standpoint, this is just horrible. You just can’t let this happen. So, what you are going to do enable unique Title and Description tag for each PHP page?
Feeling clueless? Don’t worry as we are going to show you how you can do this easily by writing some simple PHP code –
First you will have to include the below line of code in the .header.php file
<title><?php echo $pageTitle; ?></title>
<meta name=”description” content=”<?php echo $pageDescription; ?>”/>
echo ‘<link rel=”canonical” href=”‘ . $pageCanonical . ‘”>’;
So, you have successfully created three variables –
- Variable for Title Tag – $pageTitle
- Variable for Meta Description – $pageDescription
- Variable for Canonical – $pageCanonical
Now, all we have to do is to define these variables in all the pages where we have included the header.php file –
$pageTitle = “9Leafs ⇝Trusted Web Designing Company in India”;
$pageDescription = “9Leafs is your trusted partner in web designing and development.
We offer professional web designing services at affordable rates.
Contact us to discuss.”; $pageCanonical = “http://www.9leafs.org/”;
In the above code, we have used the include function to invoke the header.php file and we have defined the all the three variables.
So, is not that super simple? Now, whatever changes you will make on the header.php file will get reflected in those pages where you have fetched the header.php file.