Skip to content

Instantly share code, notes, and snippets.

@yoren
Created March 19, 2016 06:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yoren/0016496f7f1d90a112f7 to your computer and use it in GitHub Desktop.
Save yoren/0016496f7f1d90a112f7 to your computer and use it in GitHub Desktop.
Remove Content From WP API Response When Listing Posts
<?php
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$params = $request->get_params();
if ( ! isset( $params['id'] ) ) {
unset( $_data['content'] );
}
$data->data = $_data;
return $data;
}
add_filter( 'rest_prepare_post', 'my_rest_prepare_post', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment