I'm using IFTTT to post images from a subreddit to my WordPress site, and then WordPress shares those images with their post titles on multiple social sites.

The problem is, IFTTT publishes blank posts on WordPress sometimes. They only have a title but no images. Now the plugin I use for sharing the posts published by IFTTT can't recognize empty posts, and it shares only their title on other social media sites since there is no image.

So my only solution is to auto delete empty WordPress posts. Is there any script or plugin to do it?

Please let me know. Thanks


You want to write a wp_insert_post_empty_content filter.

WordPress will already try and reject empty posts:

$maybe_empty = 'attachment' !== $post_type
    && ! $post_content && ! $post_title && ! $post_excerpt
    && post_type_supports( $post_type, 'editor' )
    && post_type_supports( $post_type, 'title' )
    && post_type_supports( $post_type, 'excerpt' );

but I guess that logic isn't catching your posts here. So you'll need to work out what your empty posts look like specifically and catch them too:

function wpse390344_empty_posts_filter( $empty, $postarr ) {
    if ( ! $empty ) {
        // TODO: look at $postarr - see wp_insert_post() documentation for format
        //       and decide if this is an empty post you want to reject.
        //       If it is, return true.

    return $empty;
add_filter( 'wp_insert_post_empty_content', 'wpse390344_empty_posts_filter', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.