<?php
/**
* Remove "_links" from REST responses of the post type "post".
*
* @see https://stackoverflow.com/a/53505460
* @see https://developer.ww.wp.xz.cn/reference/hooks/rest_prepare_this-post_type/
*/
add_filter(
'rest_prepare_post',
function ( $data, $post, $request ) {
foreach( $data->get_links() as $_linkKey => $_linkVal ) {
$data->remove_link( $_linkKey );
}
return $data;
},
1,
3
);
The above code should remove _links for the post type post.
For the taxonomy variant, the filter would follow a similar pattern, but would attach to rest_prepare_{taxonomy_name}: https://developer.ww.wp.xz.cn/reference/hooks/rest_prepare_this-taxonomy/
Thanks a lot Paul! That worked! 🙂
One more question, if I were to remove any additional parameters, how could I do that? Let’s say I want to remove description from custom taxonomy REST API response or guid, modified, status, etc. from custom post type?