Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active November 3, 2021 05:24
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 mishterk/cdb241c1deda8afb6bd73efdfcc9da50 to your computer and use it in GitHub Desktop.
Save mishterk/cdb241c1deda8afb6bd73efdfcc9da50 to your computer and use it in GitHub Desktop.
WordPress REST API examples
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'my-namespace/v1', 'some/route', [
'methods' => [ 'GET' ],
'permission_callback' => '__return_true',
'callback' => function () {
// You can return arrays or objects here — WordPress will
// format them for output as JSON.
return [
'some' => 'custom',
'data' => 'can',
'go' => 'here',
];
},
]
);
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment