WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

In a plugin I use ajax to get_option() which takes much longer than it has to because entire wp gets loaded.

How do I set things up so that it (my ajax) loads only what is needed? (get_option())

share|improve this question
up vote 4 down vote accepted

If you're building something for public consumption (a plugin, a theme, etc) use admin-ajax.php like you should because that is the appropriate and accepted way to do things and gives your end users the power they need to change and modify things if they so choose.

Beyond that, the best you MAY be able to do is use the SHORTINIT constant. Define it in a custom php file, then require wp-load.php and do what you need to do. SHORTINIT stops most of the WordPress core from being loaded.

define('SHORTINIT', true);
require '/path/to/wp-load.php';
// you'll have the basic API here, including `get_option`. Do stuff.

If you do this outside the WP core, you'll have to guess where wp-load.php may be -- you won't have any ABSPATH contant to guide you. That's a risky bet unless you're in full control of the system. In other words, if this is a custom, not publicly-released thing, go for it. Otherwise, use admin-ajax.php.

share|improve this answer

Another Method is to add this code into functions.php (or in plugin), without need of require '/path/to/wp-load.php'... but it will not be as faster as SHORTINIT :

function MyFuncion(){
    if (isset($_POST['mynamee'])) { echo get_option('my_nm');}

//1) Execute directly
//2) Hook into the EARLIEST ACTION:  
add_action('muplugins_loaded', 'MyFunction',1);


share|improve this answer

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.