Title: Including wordpress functions
Last modified: August 30, 2016

---

# Including wordpress functions

 *  [battleooze](https://wordpress.org/support/users/battleooze/)
 * (@battleooze)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/including-wordpress-functions/)
 * Hello, I’m coding first plugin (and probably doing this wrong!). My current directory
   structure goes something like this:
 * -index.php has plugin declaration in comments at start of file
    -standard.php
   has things like constant declarations & my way of including wp-load into other
   files which goes like this:
 * function iam_require_load()
    { //suppress warnings of constant if(@constant(‘
   ABSPATH’)!=null){ require_once ABSPATH.’wp-load.php’; } else { require_once realpath(‘../../../’).’/
   wp-load.php’; } }
 * Which I’m assuming is a bad way to do that. Basically I made this with because
   I need to use things like “get_site_url()” and $wpdb in various files both in
   the same directory and in my templates sub directory.
 * I read a [couple](https://frankiejarrett.com/2012/04/the-simplest-way-to-require-include-wp-load-php/)
   [blogs](http://ottopress.com/2010/dont-include-wp-load-please/) which said I 
   should not be including wp-load in a production wordpress and so I exclaimed “
   But then how do I include these things I need!?!?” Which lead me to the assumption
   that I’m doing something horribly wrong.
 * Any help is much appreciated! : D

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Joe Ponzio](https://wordpress.org/support/users/new-nine/)
 * (@new-nine)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/including-wordpress-functions/#post-6751749)
 * You don’t include it in your plugin because it will already exist. The plugin
   is loaded when WordPress is loaded; so, you don’t need to call wp-load.php.
 * So basically any time your plugin loads, functions like `site_url` should already
   be available to your code when it executes.
 * The only time you would need to call wp-load.php is if you need to load WordPress
   in an external script and WordPress would not otherwise be loaded. But again –
   you’re building a WordPress plugin which only runs when the site is loaded up,
   so you don’t need to include wp-load.php.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/including-wordpress-functions/#post-6751810)
 * > The only time you would need to call wp-load.php is if you need to load WordPress
   > in an external script
 * And even then you do not actually call wp-load.php. If you want anyone to be 
   able to use your plugin you must never include or require wp-load.php, _never
   ever_.
 * So what to do with an external script that needs to access WP functions? You 
   have 3 choices. 1) Use AJAX. 2) Make your external script into a page template,
   then add a page based on it, then load that page. 3) Run your requests through
   admin-post.php, which is sorta like AJAX callbacks except you don’t necessarily
   need javascript client side.
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/including-wordpress-functions/#post-6751841)
 * > And even then you do not actually call wp-load.php. If you want anyone to be
   > able to use your plugin you must never include or require wp-load.php, never
   > ever.
 * While true from within WordPress, one must include wp-load.php to access WordPress
   from an external-to-WordPress PHP script.
 *  [Joe Ponzio](https://wordpress.org/support/users/new-nine/)
 * (@new-nine)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/including-wordpress-functions/#post-6751865)
 * Great discussion! We’ve built some very large, complex websites using WordPress,
   and have on many occasions brought in tons of third party libraries and code 
   via custom themes and plugins, and I can’t remember the last time we’ve needed
   to call `wp-load.php`.
 * DionDesigns is correct – if you’re trying to access WordPress from another application,
   you’d have to call it. But if you’re building a WP theme or plugin, or otherwise
   using WP as your main framework, and you find yourself calling `wp-load.php`,
   there’s almost certainly a better way to do what you’re trying to achieve.
 * `wp-load.php` is used when WordPress isn’t loaded and you need it to do so. If
   you’re working in WordPress…it’s loaded 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Including wordpress functions’ is closed to new replies.

## Tags

 * [require()](https://wordpress.org/support/topic-tag/require/)
 * [wp-load](https://wordpress.org/support/topic-tag/wp-load/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 4 participants
 * Last reply from: [Joe Ponzio](https://wordpress.org/support/users/new-nine/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/including-wordpress-functions/#post-6751865)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
