2

I've started creating a custom html page for the first time and i've hit a bump. The code in the header will be the same in all my pages , so i want to put it in an external file (header.php) and just put 1 line of code in all my pages to link to it but it doesn't seem to be working .

  • Note - I want to include just basic html code ( not a function ) - i'm thinking that's why its not working but not sure.

HTML file :

<body>

<?php include('header.php') ?>     // didn't work
<?php get_header(); ?>      // didn't work

<div class="content"> </div>

</body>

PHP File :

<h1>TITLE</h1>

When i put the code directly on the page - it shows "TITLE"

When i try include or get_header , i get a blank page . I checked the codex and online posts but i've not been able to fix it .

Any help would be appreciated - Thanks

Rayan Bouajram
  • 743
  • 5
  • 12
John_Nil
  • 165
  • 2
  • 4
  • 17
  • 2
    `` Try that. Concerning get_header(); is a wordpress function (or whatever other platform use it) – bastienbot Feb 01 '14 at 18:08
  • 1
    There could be many reasons why you're seeing a blank page. How are you previewing your page? Are you using the file:// protocol, localhost, or web server? – Rayan Bouajram Feb 01 '14 at 18:10
  • localhost/url - using xampp on my pc – John_Nil Feb 01 '14 at 18:11
  • 1
    If you're using XAMPP, I'm guessing your site is under `htdocs/url`... You've mentioned you're using an HTML file, could you verify that your files are using the .php extension and not .html? (I will unproudly admit that I've found files named index.php.html in the past.) Also, check the XAMPP Control Panel to ensure Apache is running. – Rayan Bouajram Feb 01 '14 at 18:17
  • 1
    @John_Nil instead of using `include()`, use `require()`. PHP will spit out an error, which will probably tell you why it's not displaying. :). – Rayan Bouajram Feb 01 '14 at 18:38
  • 1
    Found a way to make it work - I changed my index.html to index.php and it seems to be working now - Is there any difference having a page with .php instead of .html ? Thanks a lot for your help guys – John_Nil Feb 01 '14 at 19:07
  • @John_Nil a .php file can render exactly the same as .html, but does not allow the server to read `` syntax (it's important to understand that PHP is a server-side language, unlike HTML which is generally client-side) – Rayan Bouajram Feb 06 '14 at 07:53

2 Answers2

0
<?php include("dyn_layout/cbside_php.php"); ?>

This works for me... just don't forget to rename your files to .php extension... including the file where the insertion is made.

0

Try in your header.php:

<?php
echo "<h1>TITLE</h1>";
?>

Then where you want to insert the header:

<?php include '/header.php' ?>

The / character makes the path to header.php relative to your root.

George Bora
  • 1,618
  • 6
  • 26
  • 45