Title: Prevent saving empty posts
Last modified: November 24, 2017

---

# Prevent saving empty posts

 *  [squasher](https://wordpress.org/support/users/squasher/)
 * (@squasher)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/prevent-saving-empty-posts/)
 * Hi,
 * I noticed that it is possible to save empty posts (no title, content and excerpt).
   I think this is very strange. I tested it on various sites to see if I’m right
   and I believe I am.
 * How can I prevent this? I don’t want this behaviour, especially with custom post
   types.
 * In post.php I found the following part:
 *     ```
       if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
       		if ( $wp_error ) {
       			return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
       		} else {
       			return 0;
       		}
       	}
       ```
   
 * I would expect this to throw an error but I guess I’m wrong.
 * So next I tried this filter, but that didn’t work:
 *     ```
       //We do not want to be able to save posts without title and content:
       add_filter ('wp_insert_post_empty_content', function() { return false; });
       ```
   
 * So how can I prevent saving empty (custom) posts? Any suggestions?
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/prevent-saving-empty-posts/#post-9719778)
 * That empty content filter defaults to false, you should return true for that,
   at least that appears to be the intention. On my site returning true causes all
   sorts of warnings and strange behavior. It does prevent empty posts though.
 * Another thing you could do is hook ‘wp_insert_post_data’. If the passed data 
   fields are empty, simply die with an error message. Check for specific details
   like post type to avoid dying needlessly.

Viewing 1 replies (of 1 total)

The topic ‘Prevent saving empty posts’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/prevent-saving-empty-posts/#post-9719778)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
