Support » Developing with WordPress » Nonce header stopped working wordpress post rest api

  • Resolved djmiller78



    I had a working post route with nonce header in wordpress using npm. Now it only works if I comment out the nonce header. With nonce header, console returns message “(routename) not defined”. Route is recognized with nonce and WP_REST_SERVER::READABLE method, but not with POST method.

    JS side:

        var updateLikes = new XMLHttpRequest(); 
        updateLikes.setRequestHeader('X-WP-Nonce', SB.nonce);

    php side:

        add_action('rest_api_init', 'sbLikeRoutes');
        function sbLikeRoutes(){
           register_rest_route('SB/v1', 'manageLike' , array(
           // 'methods' => WP_REST_SERVER::READABLE,
           'methods' => 'POST',
           'callback' => 'SBPostLike'
  • You must be logged in to reply to this topic.