Question: In Wordpress editor (TinyMCE), whenever I switch between 'Visual' and 'Text' mode, all my HTML formatting gets removed. That includes tabs (indents) and line breaks. Sometimes, even elements and elements attributes are removed.

I searched a lot about this issue, wich is actually a pretty common problem for many users, but after browsing 10 pages of Google, I got nothing but a plugin called **[Preserved HTML Editor Markup Plus](https://wordpress.org/plugins/preserved-html-editor-markup-plus/)**. The problem is this **[plugin conflicts with Yoast SEO plugin](https://wordpress.org/support/topic/conflict-when-using-with-yoast-seo/)**.

Is there any thing I can do to preserve the HTML formatting, allowing both modes (Visual and Text) and not knowingly compromising other plugins?

Answer: 
You should try TinyMCE Advanced Plugin. 

[TinyMCE Advanced](https://wordpress.org/plugins/tinymce-advanced/) have set to Stop removing the `<p> and <br /> tags` when saving and show them in the HTML editor.

Try it after removing another editor plugin which you have installed to prevent conflict with other. 

The second option is [Raw HTML](https://wordpress.org/plugins/raw-html/) plugin. It has also a good feature to prevent HTML formatting. You can use `[raw]` shortcode like `[raw] YOUR HTML [/raw]` to prevent HTML formating.

You can try this both plugin once. Hope one of from these option work for you.

Thanks.
Wordperss has **wp\_kses** function that only allow certain html tag in post content. 

If you want to certain html tag / attributes allowed in your post content , you need to remove kses filter ( **kses\_remove\_filter** ) functions added in your theme / plugin. 

**Reference** 

<https://codex.wordpress.org/Function_Reference/wp_kses>

<https://developer.wordpress.org/reference/functions/kses_remove_filters/>