How to Dynamically Change Meta Tags in every Pages using PHP
Submitted by nurhodelta_17 on Friday, April 20, 2018 - 23:45.
Getting Started
For example, you have this simple meta data in your header.php template.- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="url" content="Your Site Url here">
- <meta name="description" content="Your Site description here">
- <meta name="keywords" content="Your set of keywords for the page ">
- <meta name="author" content="John Doe">
- ................................
- <!-- css and scripts here -->
- </head>
Code:
In order to create a unique meta data for another page and reuse your header.php template, do the ff. 1. Assign variables for your meta tag in your header.php. Example:- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="description" content="<?php echo $description; ?>">
- ............................
- <title>How to Dynamically Change Meta Tags in every Pages using PHP</title>
- <!-- css and scripts here -->
- </head>
- <?php
- $description = "Your site description here";
- include 'header.php';
- ?>
Add new comment
- 1887 views