WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a plugin that has a php file in the plugin directory which is accessed directly via a custom rewrite url.

I need this file to be able to use the three functions mentioned in the title.

At the moment, I am including the wp-load.php file which gives me access to all of these functions. However, I've been reading that wp-load shouldn't be included because it may not always be in the same place and it includes wordpress files that may not be needed.

This is how I'm including wp-load:

$wp_base = explode($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME']);
require($wp_base[0] . '/wp-load.php');

I've found that the functions I need are located in these wordpress files:


Should I instead include only these three files, and will they always be located in the same place?

Or is there a better way to go about do this?


share|improve this question
There is most certainly a better way to do this. If you include these files, you are setting yourself up for all sorts of maintenance issues. What are you trying to do by executing a PHP file directly? My guess is that there is a better way to do what you want. – tollmanz Apr 8 '12 at 1:46
up vote 0 down vote accepted

These functions are already accessible if you use the rewrite API. When your file is parsed WordPress has loaded already, so do not include core files a second time.

share|improve this answer
The functions don't seem to exist without including wp-load, but I'm using the same method to create my rewrite as explained in the link you provided. After the rewrite is created I found this line added to my .htaccess file: RewriteRule ^mypage$ /wp-content/plugins/plugin-name/mypage.php [QSA,L] Wouldn't this bypass wordpress and load the php file directly? – Sarathi J. Hansen Apr 8 '12 at 3:18
Then something strange happend. Usually, there is no need for an extra line in the .htaccess. – toscho Apr 8 '12 at 3:30
I think the problem is that I'm not rewriting to index.php so it adds the rule to htaccess instead of running it through wordpress. But I'm not sure how I could use index.php and still have it load my page. – Sarathi J. Hansen Apr 8 '12 at 3:58
Did you read the page I linked to? Everything is nicely explained there. For a code example see my Speed Dial Plugin. – toscho Apr 8 '12 at 4:01
Thank you! I guess I didn't read the article well enough, but I got it to work by adding the query variable then requiring my php page on the template_redirect hook. – Sarathi J. Hansen Apr 8 '12 at 4:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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