Skip to content

Instantly share code, notes, and snippets.

@pinalj
Last active November 30, 2017 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinalj/d40169c9b774cb335d94d2986a6970ee to your computer and use it in GitHub Desktop.
Save pinalj/d40169c9b774cb335d94d2986a6970ee to your computer and use it in GitHub Desktop.
Create custom REST route
<?php
add_action( 'rest_api_init', 'my_register_route' );
function my_register_route() {
register_rest_route( 'my-route', 'my-phrase', array(
'methods' => 'GET',
'callback' => 'custom_phrase',
)
);
}
function custom_phrase() {
return rest_ensure_response( 'Hello World! This is my first REST API' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment