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

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

  2. User Avatar
    mo003akes
    Permalink to comment#

    but is it safe???

  3. User Avatar
    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. User Avatar
    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. User Avatar
    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. User Avatar
    Latte
    Permalink to comment#

    I’ve used this on my website http://www.latte-internet.com The htaccess things are pretty useful.

  7. User Avatar
    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

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Submit a Comment

icon-closeicon-emailicon-linkicon-menuicon-searchicon-tag