Output pure JSON wordpress

You will want to have your own url structure to output your “non html” output. Actually there are several ways, and it might be up to coding style preference to select one

  1. Add a Page and a template for the page that does what you need. You don’t have to output any html even in the theme hierarchy execution path, so you can have a page template which does not call get_header/get_sidebar/get_footer and just output the json from the url parameters. This approach is probably more appropriate for a theme then a plugin

  2. Use the admin-ajax.php end point. If there is no reason to have a fancy end point for your requests it will just work and you can follow all the examples about how to write ajax for wordpress on the web

  3. use the new json endpoint introduced in 4.4. It is new and I could not find the actual API for that, but it does exist and probably the best future looking solution

  4. use add_rewrite_rule to create your own end point and write the appropriate handler.

The technical differences between all the options in the end, is mainly how you set them up and the format of the url. Otherwise “best” and “better” are a matter of taste or other requirements (core json handling might be disabled, if you want to make sure your plugin will work even then, then the json endpoint path is not for you).