Reputation: 768
I am having trouble including unique <meta>
tags across many pages that share a universal header.
The header is included using PHP where one header.html file is prepended to all of my pages. The pages where initially structured as follows:
The page where header.html is included
<?php include('header.html');?>
<div id="contents">...</div>
<?php include('footer.html');?>
and header.html contained this structure
<html>
<head>
<title>...</title>
<meta>...</meta>
<link>...</link>
<scripts>...</scripts>
</head>
<body>
I am now more aware of the importance of <title>
and <meta>
tags for many aspects of SEO and I am conscious that these must be properly formatted for each page. To combat this I have now structured my pages like this:
The page where header is included
<html>
<head>
<title>...</title>
<meta>...</meta>
<?php include('header.php');?>
<div id="contents">...</div>
<?php include('footer.html');?>
and header.html contains this new structure
<link>...</link>
<scripts>...</scripts>
</head>
This just seems inefficient and I feel it deviates from the benefits of using PHP includes in the first place.
In all this question my be to broad and not specific enough. How can I include <meta>
tags in a page without having to hard code them into every page, achieving the design benefits gained in a template approach? Is there a more modern design approach that overcomes these problems that I could implement?
Upvotes: 1
Views: 794
Reputation: 117
A better concept in my eyes is to use a template engine such as smarty or something similar. That way you would just load the required templates per page you want to show. Apart from that I love to seperate php code from html which you achieve with that too.
Another way would be to just identify your document by its document name within php and switch in a case or if whatever needs to be included in the header.
Upvotes: 1