kevinzf
kevinzf

Reputation: 193

Wordpress custom endpoint returns 404

I followed this tutorial to create custom endpoints. But, it always returns 404.

I added code below to function.php

add_action('rest_api_init', function() {
  register_rest_route('awesome/v1', '/awesomeparams', array(
    'methods' => 'GET',
    'callback' => 'get_awesome_params',
    'args' => array(),
    'permission_callback' => function () {
      return true;
    }
  ));
});
function get_awesome_params( $data ) {
    return "aaaa";
}

When I trying to access: http://smap.cas.mcmaster.ca/wp-json/awesome/v1/awesomeparams

It shows 404:

enter image description here

I checked many other posts, but still can't find a solution. Can I get some help?

Thanks!

Upvotes: 0

Views: 295

Answers (1)

Pipo
Pipo

Reputation: 518

Did you flush your permalinks? Go to Wordpress admin -> Settings -> Permalinks and click save, It should flush your permalinks and then It should work.

Upvotes: 2

Related Questions