Append / Prepend Files

Rather than having to call / include a file you need on every single page, you can have them automatically prepended (top of file) or appended (bottom of file) automatically through your .htaccess file.

php_value auto_prepend_file "/real/path/to/file/functions.php"
php_value auto_append_file "/real/path/to/file/footer.php"


  1. johndoe
    Permalink to comment#

    nice – you can use also the php.ini for this

  2. mo003akes
    Permalink to comment#

    but is it safe???

  3. Seth
    Permalink to comment#

    I’m completely new to this stuff… for that one tutorial you did for Kailin Yung, could you use this to get those curly things to appear on the h2 tags? and if so/not, how would you go about doing that?

  4. Seth
    Permalink to comment#

    I’m quite new to this stuff. In the tutorial where you made a new theme for Kailin Yung, could this be used to get those curly things onto all the h2 tags? haha i’m trying my hardst to find out how to do that and just cant figure it out.

  5. Sam Purcell
    Permalink to comment#

    Hey Chris, this is a very useful tool, so thanks. Now, is there any way to selectively append and prepend files? I have pages where I need no footer or header. Can I include a few lines in my htaccess to negate the action for certain files? Because my htaccess file and all of my files are in the head directory, switching file locations doesn’t seem like it’d work, and I don’t know enough to do anything else. Thanks for the snippet!

  6. Latte
    Permalink to comment#

    I’ve used this on my website The htaccess things are pretty useful.

  7. Sergey Simonyan
    Permalink to comment#

    And then some other poor guy, charged with maintaning your code after you leave, will loose his mind trying to understand why he has some alien includes interferring with his files.

    Or somebody comes and says: “Hey! Apache is history! Lets move to ngingx / lighttpd + php-fpm! Oh… wait. How come your code has to be refactored for this? This should be a simple matter of writing new configuration file!”

    Or you can manage PHP matters with PHP methods, and, for example, use an amazing thing called “Class Autoloading” — something that all modern PHP frameworks utilize:

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

We have a pretty good* newsletter.