I 开发者_如何学编程am trying to have a WordPress plugin returning some custom json data, when a specific parameter is passed through the URL. The problem is that I cannot find a way to prevent it to display anything. I want to strip any display and only 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 just returns the json data returned from a triggered function (and removing any default display).
Is there any way to do that?
My purpose is to have that plugin returning some json data, and acting like an API, living within my plugin.
Thanks
Make a template called jsonpage.php Use this template for your page
if ($_REQUEST['api']) {
$data = array();
header('Content-type: application/json');
return json_encode($data);
} else {
// show header, page content, etc.
}
精彩评论