I get 500 error on wp-json.

if I try to echo get_rest_url() I get example.com/wp-json, which then gives me error 500. I added RewriteCond %{REQUEST_URI} !^/wp-json to my .htaccess, which gave me 404 error instead.

I use postname as settings for permalinks. I've tried http://example.com/?rest_route=/wp-json/v2/posts as well, and it gives me error 500.

EDIT: Okay, I turned on wp_debug. Now I get the error: Fatal error: Call to undefined function register_rest_route() in /customers/0/2/1/. So this is my new error. Any clue for this?

  • 1
    If you get a 500 error, you should be able to check the server's error log for the details of the error.
    – MrWhite
    Apr 17, 2018 at 11:56
  • 1
    Sweet, thanks. I got the error: Call to undefined function register_rest_route(). Any clue what that is? Apr 17, 2018 at 12:09

2 Answers 2


Are you trying to use that function without first initiating it in an action? It should be done like so:

add_action( 'rest_api_init', 'add_custom_users_api');

function add_custom_users_api()
    register_rest_route( 'route', array(
                                'methods' => 'GET',
                                'callback' => 'function',

Create a .htaccess file with

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Your Answer

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

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