Grow your CSS skills. Land your dream job.

Last updated on:

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"

Comments

  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. Permalink to comment#

    I’ve used this on my website http://www.latte-internet.com 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: http://php.net/manual/en/language.oop5.autoload.php

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like ```this```. You don't need to escape code in backticks, Markdown does that for you.

Sadly, it's kind of broken. WordPress only accepts a subset of HTML in comments, which makes sense, because certainly some HTML can't be allowed, like <script> tags. But this stripping happens before the comment is processed by Markdown (via Jetpack). It seems to me that would be reversed, because after Markdown processes code in backticks, it's escaped, thus safe. If you think you can fix this issue, get in touch!

If you need to make sure the code (typically HTML) you post absolutely posts correctly, escape it and put it within <pre><code> tags.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".