How to prevent WordPress from removing line-breaks, <p>, <br> and <div> tags in post contents and other areas

By default WordPress editor remove line-breaks, paragraphs and some other empty tags that it think is not important.

You can avoid this behavior by adding this code to the end of functions.php theme or child theme file:

// stop wp removing div tags
function magnium_tinymce_fix( $init )
    // html elements being stripped
    $init['extended_valid_elements'] = 'div[*], article[*]';
    // don't remove line breaks
    $init['remove_linebreaks'] = false;
    // convert newline characters to BR
    $init['convert_newlines_to_brs'] = true;
    // don't remove redundant BR
    $init['remove_redundant_brs'] = false;
    // pass back to wordpress
    return $init;
add_filter('tiny_mce_before_init', 'magnium_tinymce_fix');

Additionally you can check this article about WordPress line-breaks behaviour: