How to modify post content?

I still haven’t figured this out yet.
Is this the right way? I tried $_POST['content'] = "nothing" and $_POST['content'] = 0 neither work for me. I’m using following way

function changeContent() {
     $_POST['content'] = "nothing"; 
add_action('publish_post', 'changeContent');

I want to change the content before it’s written into the database.

Solutions Collecting From Web of "How to modify post content?"

You might check out the content_edit_pre filter.

Your example would then look like this:

function wpse89725_pre_edit_content( $content, $post_id ) {
   $content = "nothing";
   return $content;
add_filter( 'content_edit_pre', 'wpse89725_pre_edit_content', 10, 2 );

You can read more about this filter in the Codex:


You can also try the edit_post_content filter:

add_filter( 'edit_post_content', 'my_pre_edit_content', 10, 2 );

Since we have in the file /wp-includes/post.php these lines:

 $value = apply_filters("edit_{$field}", $value, $post_id);
 // Old school
 $value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id);

both of these filters should work, but the filters *_edit_pre seems to be on the way out and replaced by edit_*.