This plugin will be most helpful to developers. It allows you to more easily declare routes and have them execute callbacks that you define in your own theme/plugin code. From there, you can either take over the rendering of the page entirely, or pass back content to be rendered using the active theme’s default page template.
An example of registering a route with the system is:
The above example will call the function
my_test() when a
GET request is received for the url
You can pass it any PHP Callable. This means that methods on your objects are fair game as a callback.
In terms of what you return, the router accommodates several cases:
– Boolean value — If `FALSE` is returned, then WordPress will display the active theme’s 404 page. If `TRUE` is returned, then an empty page is going to be rendered (using the default page template for your active WordPress theme).
– String value — If a string is returned, then the page title is set to an empty string, and whatever string you returned will be in place of the content.
– Array value — Returning an array allows you to control the title and content of the page that will be displayed to the user. An example of a valid returned array is:
It is worth noting that your callback can do whatever it wishes, and then simply exit if, for instance, you wanted to render JSON and prevent the WordPress page template being rendered.
Below are two examples of registering routes and callbacks for the router: