rest_prepare_post
rest-apiFilters the REST API response for a single post before it's sent
rest_prepare_post lets you add or remove fields on the /wp/v2/posts response without touching register_rest_field — useful for last-mile shaping of what the API returns.
Signature
apply_filters( 'rest_prepare_post', WP_REST_Response $response, WP_Post $post, WP_REST_Request $request );Example
add_filter( 'rest_prepare_post', function( $response, $post ) {
$response->data['reading_time'] = ceil( str_word_count( $post->post_content ) / 200 );
return $response;
}, 10, 2 );Common Use Cases
- Add computed/derived fields to the REST response
- Strip sensitive fields from public API output
- Reshape data for a headless front-end


