Using php to automate headers and footers?

4 replies
  • WEB DESIGN
  • |
Has anyone tried to use php to automate creating headers and footers for their html sites?

Here is what I mean. Lets say you have an site that is made up of 15 html pages. You then decide to change one of the links in the footer. Now you have to go back and change the footer information in every single one of those 15 html pages.

But if there were php, you can have a function for header and another for footer. All you do then is to change the link in that one function and it propagates out to all 15 pages.

Any ideas or thoughts about this.

Thanks
#automate #footers #headers #php
  • Profile picture of the author Brandon Tanner
    Yep. This is how I do all of my sites now, and it certainly makes it MUCH easier to maintain!

    It's very easy to set up...

    Simply create a new php file named header.php, and put your HTML code for your header in that file.

    Then simply "include" that file in your regular webpages where you want the header code to appear.

    For example, in your home page where you want your header code to appear, add the following line of code (assuming that you put header.php in the same folder as your other webpages)...

    <?php include ("header.php"); ?>

    Now add that line of code in all of the pages where you want the header code to appear.

    Just be sure that you give ALL of those webpages a .php extension (index.php, page2.php, page3.php, etc etc).

    Now whenever you want to make any changes to the header, all you have to do is edit the header.php file, and it will automatically update the header across all of the pages!

    And of course you can do the same thing with the footer, or with any other parts of a webpage.

    That's all there is to it. Let me know if you have any questions!
    Signature

    {{ DiscussionBoard.errors[6470820].message }}
  • Profile picture of the author hbteos234
    Thanks Brandon. I like this approach as it seems like a much easier way to do it. The only difference would be that the files would have to be .php files instead of .html. Not sure if this would have any effect on seo, although I doubt it

    Thanks
    {{ DiscussionBoard.errors[6478437].message }}
    • Profile picture of the author Brandon Tanner
      Originally Posted by hbteos234 View Post

      Thanks Brandon. I like this approach as it seems like a much easier way to do it. The only difference would be that the files would have to be .php files instead of .html. Not sure if this would have any effect on seo, although I doubt it

      Thanks
      No problem, glad I can help! And it has zero effect on SEO.
      Signature

      {{ DiscussionBoard.errors[6478914].message }}
  • Profile picture of the author xtrapunch
    If you are looking to create a large website, consider using a CMS such as Joomla, WordPress. Ages ago, I used iFrames to embed common headers and footers to all webpages of a site.
    Signature
    >> Web Design, Wordpress & SEO - XtraPunch.com <<
    Web Design & SEO Agency | Serving World Wide from New Delhi, India

    {{ DiscussionBoard.errors[6478550].message }}

Trending Topics