Skip to main content
Login Join
Snippet · PHP

Disable WP JSON API

Shared by Nazim Husain · April 23, 2026

21 views
Back to Snippets

Disable WordPress Json API endpoint for for security purpose

// Disable WP JSON API
add_filter( 'rest_authentication_errors', function( $result ) {
    if ( ! empty( $result ) ) {
        return $result;
    }
    if ( ! is_user_logged_in() ) {
        return new WP_Error( 'rest_not_logged_in', 'You are not authenticated.', array( 'status' => 401 ) );
    }
    return $result;
});
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments