Might want to use include
instead of require
, depending on whether you want the page request to fail with a fatal error if for some reason the file cannot be found/read (require
will fail, include
will just log a warning). The _once
part for either of them is probably not really serving any purpose in this case, as you probably are not trying to define any PHP classes/functions in the included file?
My personal preferred method over the years has been to create a file that has a function for each "boiler plate" part of the page. Then I require_once
that file, and call the relevant function where needed.
<-?php // had to add "-" to php tag for the forum to allow it
require_once $_SERVER['DOCUMENT_ROOT'] . "/path/to/page_functions.php";
echo page_head('Title', 'list, of, keywords');
echo page_menu();
echo page_sidebar();
?>
<h1>My Page</h1>
<p>Lots of amazing content here</p>
<-?php // had to add "-" to php tag for the forum to allow it
echo page_foot();