June 30, 201115 yr Hello, I have been using Wordpress recently and like the idea of having the header and footer in separate files so I can just update one file instead of going through all of my html files and changing things individually. Can I simply put my all of my header and head tags etc into a header.php file and use <?php get_header(); ?> at the top of my index.html file or does this only work in Wordpress I dont know much about PHP, if anyone understand what I want to do could you try to explain it simply to me please. Thanks in advance for the help.
June 30, 201115 yr You can't use it outside of WordPress without recreating the function but you can use a simpler version with php files. Lets say you have the following files: index.php header.php footer.php You would create index.php as the following: <?php include('header.php'); ?> <!-- index code --> <?php include('footer.php'); ?> Your pages need to be in .php format, they don't have to have php coding though.
June 30, 201115 yr Author Thanks I just used the code, that is brilliant that will save me so much time I assume I can use it for any file e.g. <?php include('navbar.php'); ?> etc If you have any other useful things like this or know of any good resources please let me know. Thanks faevilangel
June 30, 201115 yr Yes, use it for whatever element you wish to be included (nav, header, footer, sidebar) I currently have my social links bar included that way too. Glad to see somebody learning something other than Wordpress, kudos!
July 1, 201115 yr If you have already called your page index.html (and it's online and people may have bookmarked it as index.html) you may not want to change the filename to index.php (which must happen to get the php processed). However, you can add code to a .htaccess file that tells the host's server to process .html extension as a .php extension, so you can then keep the name as index.html. Search or google for the .htaccess code.
July 1, 201115 yr If you have already called your page index.html (and it's online and people may have bookmarked it as index.html) you may not want to change the filename to index.php (which must happen to get the php processed). However, you can add code to a .htaccess file that tells the host's server to process .html extension as a .php extension, so you can then keep the name as index.html. Search or google for the .htaccess code. +1
July 1, 201115 yr Author Thanks for your help, this information has been very useful in building my new site. I am going to take a PHP course to help me understand its uses better. Thanks everyone
Create an account or sign in to comment