I'm trying to possess a WordPress wordpress plugin coming back some custom json data, whenever a specific parameter is passed with the URL. However , I am unable to try to prevent it to show anything. I wish to strip any display and just display the json data my function returns.

Ex: "http://mywebsite.com/mypage.php" would return my regular WordPress page.

But "http://mywebsite.com/mypage.php?api=1" would certainly returns the json data came back from the triggered function (and getting rid of any default display).

Can there be any method of doing that?

My purpose would be to obtain that wordpress plugin coming back some json data, and acting as an API, living inside my wordpress plugin.


Create a template known as jsonpage.php Make use of this template for the page

if ($_REQUEST['api']) {
  $data = array();
  header('Content-type: application/json');
  return json_encode($data);
} else {
  // show header, page content, etc.