I have a website that I have set up with includes so its templated. Can I pass information from one page to the included file? Here is the situation, I have a header.php
I put at the top of them page.php
file. Header includes all the good stuff like the head
and nav I need on every page, but how can i pass to the header.php page specific information for better SEO like OG tag stuff and page title stuff?
Header.php
<!DOCTYPE HTML>
<html lang="en">
<head>
<?php require 'head.php'; ?>
</head>
<body id="app">
<div id="page" class="page">
<div id="wrap-header" class="wrap-header">
<header id="masthead" class="site-header">
<?php require 'app-menu.php'; ?>
</header>
</div>
<div id="wrap-main" class="wrap-main">
page.php
<?php require 'layouts/header.php';
<!-- Page specific content pulled in here -->
<?php require 'layouts/footer.php'; ?>
Instead of just producing output in the include files, you should define functions. Here's a simple example.
header.php:
<?php
function show_header($title) {
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title><?php echo $title ?></title>
<?php require 'head.php'; ?>
</head>
<body id="app">
<div id="page" class="page">
<div id="wrap-header" class="wrap-header">
<header id="masthead" class="site-header">
<?php require 'app-menu.php'; ?>
</header>
</div>
<div id="wrap-main" class="wrap-main">
<?php
}
Then your main page would do:
<?php
require('header.php');
show_header("My Home Page");