<?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' ); } ?>
you can access it at the below url https://mysite.com/wp-json/my-route/my-phrase