I want to create a custom slug in WordPress and output JSON. How do I do this?
You can use pre_get_posts as suggested but simply check the global $wp object for the request url.. like so: add_action( ‘pre_get_posts’, function ($query ){ global $wp; if ( !is_admin() && $query->is_main_query() ) { if ($wp->request == ‘cats’){ header(‘Content-Type: application/json’); $cats = array(‘Hobbes’, ‘Simba’, ‘Grumpy Cat’); echo json_encode($cats); exit; } } }); (PHP 5.3+ in this … Read more