Jump to content

Include PHP header in HTML (or the other way around)?


fed

Recommended Posts

Hi guys,


 


I have a wordpress website and I'd like to use the header in a custom HTML page in which I complete the body and footer with HTML5, CSS and Javascript. What's my best option: do I create a PHP file which includes the HTML (option 1) or do I create a HTML file which includes the reference to header.php (option 2)?


 


The purpose is that I can point directly to this page (e.g. mypage.html) from both a wp and non-wp website.


 


As such, how would the code look like so that it "recognizes/finds" header.php and also links to the corresponding CSS and JS files which is required to complete the body and footer?


 


Thanks for helping me out.


 


Fed


Link to comment
Share on other sites

or do I create a HTML file which includes the reference to header.php (option 2)?

You can't use PHP in HTML files.

 

The simple option is this:

<?php

include 'header.php';

include 'page.php';

include 'footer.php';
The middle include would probably dynamically include the page you requested, but you get the idea.
Link to comment
Share on other sites

You can create a custom page template and use your themes header, footer, sidebar and replace just the content area with what you want.

<?php
/*
Template Name: CustomPage
*/
?>

<?php get_header(); ?>

<style>
<!--
  div.newcontent {
    width: 80%;
    background:#000000;
    color:#DF0101;
    text-decoration: none;
    text-align:center;
    margin-top:0px;
    margin-bottom:0px;
    margin-right: auto;
    margin-left: auto;
    padding:0px;
    }
-->
</style>
 
<?php
echo "<div class='newcontent'>";
 
echo "Any code gets added this area";
 
echo "</div>";
?>

<?php get_footer(); ?>

Save that as custompage.php inside your current themes directory

Go to your dashboard

Create a new page and name it what you desire

At the bottom right under "Page Attributes" select the "CustomPage" under "Template"

Publish your page

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.