Remove Blank Lines in Email for Unfilled Form Items

This quick tip will show you that how you can remove blank lines from Contact Form 7 during submission for optional fields which were left empty by user.


add_filter( 'wpcf7_mail_components', 'remove_blank_lines' );

function remove_blank_lines( $mail ) {
  if ( is_array( $mail ) && ! empty( $mail['body'] ) )
    $mail['body'] = preg_replace( '|\n\s*\n|', "\n\n", $mail['body'] );

  return $mail;
}

Have a tip to share with us? Please email us here.



Also checkout”Solving Common Contact Form 7 Issues

1 Comment

  • I enjoy you because of all of your effort on this blog. Debby enjoys conducting internet research and it's easy to see why. A number of us hear all about the compelling manner you create efficient ideas by means of the blog and boost contribution from other ones about this article and my child is being taught a great deal. Enjoy the remaining portion of the new year. You're carrying out a fantastic job.

Leave a comment