making posting easy

WP Include File: a WordPress Plugin

Contributions on October 14th, 2009 27 Comments

WP Include FileWP Include File utilizes the WordPress Shortcode API to include the contents and output from PHP code located in an external file within the post content.



  • Advanced form security, nonce and whitelist registration of option variable to be written in the database
  • Options stored as one array in the database to minimize database cluster
  • Unregistration of option variable from whitelist on deactivation
  • On uninstall option array is removed from the database. No trail left behind
  • Functional and user-friendly options page
  • Help page build-in

Why do you need WP Include File?

WP Include File is needed because any PHP code you type within the tinyMCE will not be rendered when the post content is displayed. Hence instead of having to create templates for each specific task/post, you can just create localized specific files and just include them in the post content using WP Include File.

WP Include File Implementation in tinyMCE

Furthermore it becomes handy when applying specific styles to certain posts that are not required by the rest of the site. Just enclose the style definitions in the style tags, save it in a file and include it in the specific post using WP Include File. Hence you save on bandwidth and load times by not loading unecessary style definitions where they are not needed.

The WP Include File plugin comes with an intuitive and functional options that will have you up and running in no time.

WP Include File options page

If you want to learn more about the philosophy behind WP Include File you can read this article: Using the WordPress Shortcode API to include an external file in the post content

Invoking WP Include File using the Shortcode within the tinyMCE

WP Include File can be invoked using the Shortcode . The Shortcode accepts three attributes: file, path and masterpath. It will include the contents of the specified file at the location the Shortcode is placed within the post content.


  1. [include file="MyCustomFile.php"]
    This will include the contents of the file MyCustomFile.php located in the directory selected on the WP Include File Options page.
    For example:
    If you selected Site Root Directory on the Options page, the full path to the file to be included will be MyCustomFile.php
    If you selected Theme Root Directory on the Options page, the full path to the file to be included will be /MyCustomFile.php
  2. [include file="MyCustomFile.php" path="/MyDirectory/demos"]
    The path attribute will override any path extension specified on the WP Include File Options page. This will include the contents of the file MyCustomFile.php located in the directory /MyDirectory/demos relative to the Root directory selected on the WP Include File Options page.
    For example:
    If you selected Site Root Directory on the Options page, the full path to the file to be included will be MyDirectory/demos/MyCustomFile.php
    If you selected Theme Root Directory on the Options page, the full path to the file to be included will be /MyDirectory/demos/MyCustomFile.php
  3. [include file="MyCustomFile.php" masterpath="/home/SomeUser/SomeDirectory/SomeOtherDirectory/MyDirectory/demos"]
    The masterpath attribute will override all the selections on the WP Include File Options page. This will include the contents of the file MyCustomFile.php located in the directory /home/SomeUser/SomeDirectory/SomeOtherDirectory/MyDirectory/demos.
    For example:
    The full path to the file to be included will be /home/SomeUser/SomeDirectory/SomeOtherDirectory/MyDirectory/demos/MyCustomFile.php


  1. I am using the path attribute and my file is not included.
    The first forward slash (/) should be included when declaring a path extension using the path attribute. For example path="/MyIncludeDirectory/Content"

Version History

  • v.
    First public release.

If you have any comments or suggestions or bugs to report please leave them below. Alternatively you can use our contact form.

Tags: ,

27 Responses to “WP Include File: a WordPress Plugin”

  1. antony says:

    is it possible to insert a query string on the inserted file? For example something like that: [include file="media.php?var=34700"]

  2. Peter Armenti says:

    Seems very useful.. but.. how do I get other plugins and short codes to work within the include file? It seems that it ignores and types of plugins or short codes that I use in the include file. For example.. the file that I’m including is an html file (kit.html) and in that file I’m using a plugin called “WordPress Tabs Slides” in addition to another custom plugin that is called via a short tag. Is there a way I can get these to work in the included html file? Should I change it to a php file somehow or something like that? Do I have to make a call to the plugins? I’m not sure what is needed. Could you please provide some insight? Thank you very much.

    • AmberPanther says:

      You need to give the .php extension to your file so the PHP script will be executed on inclusion. The shortcodes within the included file will not work. You will have to figure out the corresponding plugin function call to the shortcode and use that instead, in the included file.

  3. Max says:

    Can this be used to run the content of say a shopping cart within the wordpress content area, or is it really only to display a single PHP page/file?

    • AmberPanther says:

      Yes, it is intended only for including a PHP file. The goal is to be able to utilize the PHP functions within post content text, which WordPress does not allow. It can be also used to just insert CSS and/or JavaScript specific to that post.

  4. NeoSting says:

    Very good plugin, even excellent idea. But, jJust a question please :
    Do you know how i can include the 10 last posts of my blog in a page ? I mean, i cannot put two times a “if have post, while have post…” in the loop, already called by page.php
    An idea ?

    • AmberPanther says:

      Thanks for your comments. You cannot use WP Include File to include anything stored in the database. Take a look at the query_post function. It should help you achieve what you are trying to do. Create a page template and use query_post and The Loop to display your 10 last posts on the page.

  5. Jacinta says:

    Hi AmberPanther Team
    I was wondering if you can include a PDF file… It doesn’t work on first try (while a php file does work), so if there is anything I can do to display a PDF it would be a great help.
    BTW you have written a fantastic plugin in wp-include-file!!

    • AmberPanther says:

      you can include the link to the PDF file, but not the file itself. In order to display the PDF file on your page we recommend you trying one of the flash-based PDF viewers available. Thanks for your comments.

  6. Dave Casler says:

    Thanks! Yours was the third plug-in I tried and the first that worked. My goal was to create a page that my weather station can update. The weather station sends up a text file with all the data, plus five jpegs, every 15 minutes. See it in action at

  7. Jacinta says:

    Hello AmberPanther
    WP-Include File is a TRULY great plugin but the WordPress search does not look in the included files. Do you have any suggestions to make a search that will find text in the posts AND in the included WP Include files ?

    • AmberPanther says:

      Jacinta, we are glad you are enjoying WP Include File. Unfortunately, the text in the included files is not found by the WordPress native search, as it only searches the contents of the database, and not the rendered page. There are a couple of workarounds: 1. Use keywords in the included filename, its name is stored in the database and WordPress search will find it. 2. Migrate to a custom search option on your site (e.g. Google Custom Search). The search engine crawlers render the page, thus they index all the information, including the contents of the included file. Hence, searches will return it in the results. Setting up a Custom Search is relatively straightforward.

  8. Hi, great plugin you created there. Just one question: Is it possible to take into account the tag in included files? And if yes, then how? Reason is the following: I use the plugin to include a HTML file generated from LaTeX document in a post, and this document is updated from time to time. However, the document is also long enough to have a after the introduction. So how could I make your wonderful plugin to allow “read more”?

    Thanks so much!

    • Andreas.P says:

      Hello… at the moment this feature is not supported and it is not in our immediate plans to support it, as it would greatly increase the implementation complexity of the plugin. Our suggestion would be to split the html file in the parts (i.e. multiple files) you want, and then use the WP Include File shortcode to load the different files, separating each shortcode call with the more short-tag. Thank you for choosing WP Include File…

  9. Benny says:

    Hi is it possible with your program to include a php file from another web site which shows up on my website not as a link but the content of that file.
    Regards Ben

  10. Mark Spencer says:


    This is a great plugin and finally getting closer to a real CMS reusing code/content like this is great.

    I have a query regarding the ap-wpinc-general-options page with the three selections:
    + WordPress Root Directory.
    + Site Root Directory.
    + Theme Root Directory.
    Where the pre-populated site’s root directory has not gone low enough to get to where the files are which I am sharing with 3 websites in my case. What I am presented with is /home/blueysk/public_html/ and I would like /home/mysite/public_html/ /home/mysite/public_html/anotherdomain so that I can put in a path that represents a pseudo CDN, where I am sharing a little bit of content with each of the sites. Is there a way to get this lower or overide it by some syntax in the Path extension like ../../wherever/whatever or a fourth unpopulated option on the Choose you path where I can put in the part of the path I want?

    This would allow people to start building their own CDN.

    I also have two hosting sites and I could actually use a second host/domain if this option was allowed as the fourth place – for example:

    + WordPress Root Directory.
    + Site Root Directory.
    + Theme Root Directory.
    + User specified Domain/Directory/Path. [ ] (Take care and no what you’re doing etc…)

  11. Ph.Melleret says:

    If you want to use extra parameters in you included file, you may insert this code in wp-include-file, near line 105 ( the two first and last line belong to the code)
    //append file name
    $fullpath .= “/”.$file;

    $string = explode(‘?’, $fullpath);
    $fullpath = $string[0];
    $params = explode( ‘&’, urldecode( str_replace( ‘#038;’, ‘&’, $string[1])));
    for ( $i=0; $i < count( $params); $i++) {
    $param = explode( '=', $params[ $i]);
    $_GET[ $param[0]] = $param[1];
    $_GET['sender'] = 'include_file';

    //return if file does not exist

  1. [...] READ MORE >> Posted in Uncategorized. Leave a Comment » [...]

  2. [...] to do an “include,” which means the page always contains the latest data. That meant a plug-in to permit “including” some php code. If that sounds technical, it [...]

  3. [...] can read more about WP Include File here. No Responses to “WP Include File and WordPress [...]

Leave a Reply

We stop spam together!

RSS Feed
on facebook