With only WooCommerce installed the Wordpress rest api loading time is above 1.5s, this is unpractical, so i'm trying to create a custom endpoint and define SHORTINIT to true to load the minimum possible, but the custom endpoint is not available. Code is in a folder inside my theme outside of wordpress scope.

define('SHORTINIT', true);

require_once $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php';

function custom_endpoint() {
    register_rest_route( 'test', 'route', array(
                    'methods' => 'GET',
                    'callback' => 'custom_return',
add_action( 'rest_api_init', 'custom_endpoint' );

function custom_return() {
    return rest_ensure_response( 'Hello World! This is my first REST API' );
  • There's somewhat of a paradox, you want to load your custom endpoint faster by not loading themes and plugins, but you need to load themes and plugins to load your custom endpoint. I would suggest optimising your theme and any other plugins you have, 1.5s is slow, it needn't be as slow as that ( object cache? ) Additionally, rest API routes are implemented using rewrite rules, so you can't put a second entry point in your install without making server level changes to reroute just your endpoints URL to that file. Also it will always be active and can't be turned off – Tom J Nowell Oct 21 '18 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.