13

How can I load the Wordpress environment in a script, so I can use Wordpress' functions?

I need this because I need to call several functions from a script which is executed asynchronously.

1 Answer 1

22

you need to load the wp-load.php file, which will then allow you to call wordpress functions.

For example:

require( '../wordpress/wp-load.php' );

with 'wordpress' being your install root.

3
  • you can then use get_header() and get_footer() to append your themes header and footer to your app Mar 8, 2011 at 17:10
  • 4
    If you only want some Wordpress basics, like config options you can use the following before including wp-load.php: define("SHORTINIT", 1);
    – Fieg
    Mar 18, 2011 at 11:35
  • 5
    This is a little something that I use to take care of relative WordPress installation paths: $wp_path = explode('wp-content', dirname(__FILE__)); require($wp_path[0].'wp-load.php'); Sep 14, 2013 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.